/// <summary> /// 初始化连接 /// </summary> private void InitConnection() { WSOptions wsOptions = new WSOptions(); wsOptions.MaskingEnabled = true; wsOptions.MaxReceiveFrameLength = 1048576; // 包的最大长度 wsOptions.ActivityTimerEnabled = true; // init websocket client this.webSocketClient = new WebSocketClient("websocket", wsOptions); this.webSocketClient.ConnectionChanged += new WSDelegates.ConnectionChangedEventHandler(webSocketClient_ConnectionChanged); this.webSocketClient.TextMessageReceived += new WSDelegates.TextMessageReceivedEventHandler(webSocketClient_TextMessageReceived); this.webSocketClient.Error += new WSDelegates.ErrorEventHandler(webSocketClient_Error); }
/// private methods private void initWSClient() { socketioURI = "ws://" + _host + ":" + _port + "/" + NAMESPACE + "/" + VERSION + "/" + TRANSPORTID + "/" + session_id; handshakeURI = "http://" + _host + ":" + _port + "/" + NAMESPACE + "/" + VERSION + "/"; WSOptions wsOptions = new WSOptions(); wsOptions.MaskingEnabled = true; wsOptions.ActivityTimerEnabled = true; // init pusher client websocketClient = new WebSocketClient("websocket", wsOptions); // attach event handlers websocketClient.ConnectionChanged += new WSDelegates.ConnectionChangedEventHandler(websocketClient_ConnectionChanged); websocketClient.TextMessageReceived += new WSDelegates.TextMessageReceivedEventHandler(websocketClient_TextMessageReceived); websocketClient.Error += new WSDelegates.ErrorEventHandler(websocketClient_Error); Debug.Print("initialized ws client!!"); return; }