User Tools

Site Tools

blog:2021-03-03_c_websock4net_connection_status



2021-03-03 C#: Websock4Net Connection Status

  • I would like to know the current status of the websocket connection status.
  • There is a Websocket status property

Refer MSDN document, the property status has:

  • 0, None: connection not yet established
  • 1, Connecting: 這個連接正在交涉與遠端端點的信號交換
  • 2, Open: HTTP 信號交換完成之後的初始狀態
  • 3, CloseSent: 關閉訊息已傳送至遠端端點
  • 4, CloseReceived: 接收到來自遠端端點的關閉訊息
  • 5, Closed: 指示 WebSocket 關閉信號交換正常完成
  • 6, Aborted: RFU

Example Code

  • void SendToWebSocketServer(WebSocket websocket, string str)
    {
        if (websocket.State == WebSocketState.Open)
        {
            // 若該 websocket 是連線中
            ...
        }
    }

TAGS

  • 211 person(s) visited this page until now.

Permalink blog/2021-03-03_c_websock4net_connection_status.txt · Last modified: 2021/03/03 14:08 by jethro

oeffentlich