Exemplo n.º 1
0
 private void Disconnect()
 {
     isConnected = false;
     client.Dispose();
     client.Close();
     OnSocketDisconnect?.Invoke();
 }
Exemplo n.º 2
0
        /// <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();
        }