public void Disconnect() { mLoggedIn = false; ConnectionId = ""; StopSendTask(); StopHeartbeat(); if (mWebSocket != null) { mWebSocket.OnConnectionOpened -= OnWebSocketConnected; mWebSocket.OnConnectionClosed -= OnWebSocketClosed; mWebSocket.ProcessMessage -= ProcessMessage; mWebSocket.Disconnect(); mWebSocket = null; } }
public void Connect() { if (mWebSocket != null) // already connected or trying to connect { return; } Disconnect(); // clean up string url = SnipeConfig.Instance.ServiceWebsocketURL; DebugLogger.Log("[SnipeClient] WebSocket Connect to " + url); mWebSocket = new WebSocketWrapper(); mWebSocket.OnConnectionOpened += OnWebSocketConnected; mWebSocket.OnConnectionClosed += OnWebSocketClosed; mWebSocket.ProcessMessage += ProcessMessage; mWebSocket.Connect(url); }