public void Disconnect() { resultCodes = wsc.Disconnect(); if (debug > 0) { CrestronConsole.Print("\n Websocket Disconnect resultCodes: \r\n" + resultCodes.ToString()); } }
public void Connect() { try { wsc.Port = port; wsc.URL = host; resultCodes = wsc.Connect(); if (debug > 0) { CrestronConsole.Print("\n Websocket resultCodes: " + resultCodes.ToString()); } if (resultCodes == (int)WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_SUCCESS) { CrestronConsole.PrintLine("\n Websocket Connect WEBSOCKET_CLIENT_SUCCESS: " + host + ":" + port.ToString()); keepAliveMessageReceived = false; keepAliveCounter = 0; keepAliveReconnect = false; keepAliveTimerRepeatTime = 5000; keepAliveTimer.Reset(1000, keepAliveTimerRepeatTime); if (debug > 0) { CrestronConsole.PrintLine("\n Websocket connected."); } resultCodes = wsc.ReceiveAsync(); if (debug > 0) { CrestronConsole.Print("\n Websocket ReceiveAsync resultCodes: " + resultCodes.ToString()); } } else if (resultCodes.ToString().Contains("WEBSOCKET_CLIENT_ALREADY_CONNECTED")) { if (debug > 0) { CrestronConsole.Print("\n Websocket re-initialize..."); } wsc.Disconnect(); } else { if (debug > 0) { CrestronConsole.Print("\n Websocket could not connect to server. Connect return code: " + resultCodes.ToString()); } Disconnect(); } } catch (Exception e) { if (debug > 0) { CrestronConsole.Print("\n Websocket Connect exception: " + e.Message); } Disconnect(); } }
//Connect Method for establishing the WebSocket Connection public void Connect() { MyWSConnection.Port = 443; MyWSConnection.SSL = true; MyWSConnection.URL = "wss://stream.pushbullet.com/websocket/" + User_Token; MyWSConnection.ConnectionCallBack = SendCallback; MyWSConnection.ReceiveCallBack = ReceiveCallback; MyWSConnectionResult = MyWSConnection.Connect(); if (MyWSConnectionResult == (int)WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_SUCCESS) { PrintString = "Connection Success!"; PrintString2 = "This is the msg: " + MyWSConnection.ReceiveAsync(); } else { PrintString = "Cannot Establish Web Socket Connection. Err Code:" + MyWSConnectionResult.ToString(); } }
public int DisconnectCallBack(WebSocketClient.WEBSOCKET_RESULT_CODES error, object obj) { try { if (debug > 0) { CrestronConsole.Print("\n Websocket DisconnectCallBack error: " + error.ToString()); } } catch (Exception e) { if (debug > 0) { CrestronConsole.Print("\n Websocket DisconnectCallBack exception: " + e.Message); } return(-1); } return(0); }
public int ReceiveCallback(byte[] data, uint datalen, WebSocketClient.WEBSOCKET_PACKET_TYPES opcode, WebSocketClient.WEBSOCKET_RESULT_CODES error) { try { string receiveBuffer = Encoding.UTF8.GetString(data, 0, data.Length); if (debug > 0) { CrestronConsole.Print("\n Websocket ReceiveCallback receiveBuffer: " + receiveBuffer); } if (receiveBuffer.Contains("webSocketClientKeepAlive")) { keepAliveMessageReceived = true; sendDataAsync("webSocketClientKeepAlive"); } else if (receiveBuffer.Contains("webSocketClientDisconnect")) { //Prepare keepAlive check routine to disconnect //We can't just call disconnect here because ReceiveCallback must return a value before the socket can disconnect. keepAliveMessageReceived = false; keepAliveCounter = 2; } else { dataReceiveEvent(receiveBuffer); } resultCodes = wsc.ReceiveAsync(); if (debug > 0) { CrestronConsole.Print("\n Websocket ReceiveAsync resultCodes: " + resultCodes.ToString()); } } catch (Exception e) { if (debug > 0) { CrestronConsole.Print("\n Websocket ReceiveCallback exception: " + e.Message); } return(-1); } return(0); }
/// <summary> /// Connect to the Pushbullet Websocket to monitor for Pushes /// </summary> public static void connect() { wsc.Port = 443; wsc.SSL = true; wsc.SendCallBack = SendCallback; wsc.ReceiveCallBack = ReceiveCallback; SendData = System.Text.Encoding.ASCII.GetBytes(DataToSend); wsc.URL = "wss://stream.pushbullet.com/websocket/" + Access_Code; wrc = wsc.Connect(); if (wrc == (int)WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_SUCCESS) { CrestronConsole.PrintLine("Websocket connected \r\n"); } else { CrestronConsole.Print("Websocket could not connect to server. Connect return code: " + wrc.ToString()); } }
/// <summary> /// Connect to the Pushbullet Websocket to monitor for Pushes /// </summary> public void connect() { wsc.URL = "wss://stream.pushbullet.com/websocket/" + Access_Code; wrc = wsc.Connect(); if (wrc == (int)WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_SUCCESS) { CrestronConsole.PrintLine("Websocket connected \r\n"); } else { CrestronConsole.Print("Websocket could not connect to server. Connect return code: " + wrc.ToString()); } getUserInfo(); }
private int ClientDisconnectCallBack(WebSocketClient.WEBSOCKET_RESULT_CODES resultCode, object obj) { try { if (resultCode == WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_SUCCESS) { isConnected = false; if (onConnectionStatus != null) { onConnectionStatus(0, resultCode.ToString()); } ConnectionEventArgs e = new ConnectionEventArgs(); e.ID = ID; e.IsConnected = isConnected; e.ResultCode = resultCode; OnConnectionStatusChange(e); return(1); } else { if (onConnectionStatus != null) { onConnectionStatus(0, resultCode.ToString()); } ConnectionEventArgs e = new ConnectionEventArgs(); e.ID = ID; e.IsConnected = isConnected; e.ResultCode = resultCode; OnConnectionStatusChange(e); return(0); } } catch (SocketException se) { if (debugMode) { ErrorLog.Exception(string.Format("WebSocketCleint ID {0} SocketException Occured in ClientDisconnectCallBack", ID), se); } return(0); } catch (Exception e) { if (debugMode) { ErrorLog.Exception(string.Format("WebSocketCleint ID {0} Exception Occured in ClientDisconnectCallBack", ID), e); } return(0); } finally { if (connectionRequested && !_client.Connected && autoReconnect) { _client.ConnectAsync(); } } }
/// <summary> /// Connect to the Pushbullet Websocket to monitor for Pushes /// </summary> public void connect() { PBSocket.URL = "wss://stream.pushbullet.com/websocket/" + DeviceToken; PBSocketResultCode = PBSocket.Connect(); PBSocket.KeepAlive = true; if (PBSocket.Connected) { CrestronConsole.PrintLine("Websocket connected \r\n"); PushConnected(1); } else { CrestronConsole.Print("Websocket could not connect to server. Connect return code: " + PBSocketResultCode.ToString()); PushConnected(0); } getUserInfo(); //UpdateDevice(); //UpdateDevice(Sender_Iden, "MyProcessor", "CP3", "Crestron"); }
/// <summary> /// Connect to the Pushbullet Websocket to monitor for Pushes /// </summary> public static void connect() { wsc.Port = 443; wsc.SSL = true; wsc.SendCallBack = SendCallback; wsc.ReceiveCallBack = ReceiveCallback; SendData = System.Text.Encoding.ASCII.GetBytes(DataToSend); wsc.URL = "wss://stream.pushbullet.com/websocket/" + Access_Code; wrc = wsc.Connect(); if (wrc == (int)WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_SUCCESS) { CrestronConsole.PrintLine("Websocket connected \r\n"); } else { CrestronConsole.Print("Websocket could not connect to server. Connect return code: " + wrc.ToString()); } }
public void Connect(String Url) { myWSC.URL = Url; CrestronConsole.PrintLine(myWSC.URL); error = myWSC.Connect(); if (error == (int)WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_SUCCESS) { UpdateSocketStatus(1); CrestronConsole.PrintLine("Websocket connected \r\n"); } else { CrestronConsole.Print("Websocket could not connect to server. Connect return code: " + error.ToString()); } }
public int connect() { try { ret = ws_client.Connect(); if (ret == (int)WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_SUCCESS) { CrestronConsole.Print("[WSClient.connect] websocket connected"); } else { CrestronConsole.PrintLine("[WSClient.connect] websocket could not connect, err: {0}" + ret.ToString()); } } catch (Exception ex) { CrestronConsole.PrintLine("[WSClient.connect] exception : {0}", ex.ToString()); } return((int)ret); }
/// <summary> /// Connect to the Pushbullet Websocket to monitor for Pushes /// </summary> public void connect() { wsc.URL = "wss://stream.pushbullet.com/websocket/" + Access_Code; wrc = wsc.Connect(); if (wrc == (int)WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_SUCCESS) { CrestronConsole.PrintLine("Websocket connected \r\n"); } else { CrestronConsole.Print("Websocket could not connect to server. Connect return code: " + wrc.ToString()); } getUserInfo(); }
public void Load() { CrestronConsole.PrintLine("Access Token: " + token.ToString()); ReceiveData = new byte[SendData.Length]; wsc.SSL = true; wsc.Port = WebSocketClient.WEBSOCKET_DEF_SSL_SECURE_PORT; wsc.URL = "wss://stream.pushbullet.com/websocket/" + token; wsc.Origin = "www.programbits.com"; wsc.AddOnHeader = "Access-Token" + token; wsc.Protocol = "application/json; charset= utf-8"; wsc.ConnectionCallBack = SendCallback; wsc.ReceiveCallBack = ReceiveCallback; wsc.ConnectAsync(); if (ret == (int)WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_SUCCESS) { CrestronConsole.PrintLine("Websocket connected. \r\n"); checkPushes(); } else { CrestronConsole.PrintLine("Websocket could not connect to server. Connect returncode: " + ret.ToString()); } }
/// <summary> /// Connect to the Pushbullet Websocket to monitor for Pushes /// </summary> public void connect() { wsc.URL = "wss://stream.pushbullet.com/websocket/" + Access_Token; wrc = wsc.Connect(); wsc.KeepAlive = true; if (wsc.Connected) //if (wrc == (int)WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_SUCCESS) { CrestronConsole.PrintLine("Websocket connected \r\n"); getUserInfo(); } else { CrestronConsole.Print("Websocket could not connect to server. Connect return code: " + wrc.ToString()); } //UpdateDevice(Sender_Iden, "MyProcessor", "CP3", "Crestron"); }