public void DisconnectAndDispatch(Action <ExpandoObject> event_to_dispatch) { if (DebugEnabled) { //#if DEBUG Debug.Log("[SnipeClient] DisconnectAndDispatch"); } //#endif if (mTCPClient != null) { mTCPClient.Dispose(); mTCPClient = null; } if (mWebSocketClient != null) { mWebSocketClient.Dispose(); mWebSocketClient = null; } mConnected = false; mLoggedIn = false; mHeartbeatTriggerTime = 0.0f; mCheckConnectionTriggerTime = 0.0f; if (event_to_dispatch != null) { DispatchEvent(event_to_dispatch); } ConnectionId = ""; }
/* * public void ConnectWebSocket(string host, int port = 80) * { * string url = host.ToLower(); * if (!url.StartsWith("ws://") || !url.StartsWith("wss://")) * { * url = url.Replace("http://", "ws://").Replace("https://", "wss://"); * if (!url.StartsWith("ws://") || !url.StartsWith("wss://")) * url = "ws://" + url; * } * if (url.EndsWith("/")) * url = url.Substring(0, url.Length - 1); * * if (port > 0 && port != 80) * url += ":" + port.ToString() + "/"; * * ConnectWebSocket(url); * } */ public void ConnectWebSocket() { ConnectionId = ""; if (mWebSocketClient == null) { mWebSocketClient = new SnipeWebSocketClient(); mWebSocketClient.OnConnectionSucceeded = OnWebSocketConnectionSucceeded; mWebSocketClient.OnConnectionFailed = OnWebSocketConnectionFailed; mWebSocketClient.OnConnectionLost = OnConnectionLost; mWebSocketClient.OnMessageReceived = OnMessageReceived; } mWebSocketClient.Connect(mConnectionWebSocketURL); }
private void OnTCPConnectionSucceeded() { if (mWebSocketClient != null) { mWebSocketClient.Dispose(); mWebSocketClient = null; } mConnected = true; mClientKeySent = false; mLoggedIn = false; mCheckConnectionTriggerTime = 0.0f; mHeartbeatTriggerTime = 0.0f; DispatchEvent(ConnectionSucceeded); }