private void Disconnect() { isConnected = false; client.Dispose(); client.Close(); OnSocketDisconnect?.Invoke(); }
/// <summary> /// Properly dispose all the connections and variables. /// </summary> private static void Reset() { //Reset the variables. if (ConnectedTo != null) { ConnectedTo = null; } if (ConnectedPort != 0) { ConnectedPort = 0; } if (IsConnected) { IsConnected = false; } //Kill off the thread if (socketThread != null) { socketThread.Abort(); socketThread = null; } //Kill sockets. if (socket != null && socket.Connected) { socket.Shutdown(SocketShutdown.Both); socket.Close(); socket = null; } //Tell everyone we disconnected. OnSocketDisconnect?.Invoke(); }