Ejemplo n.º 1
0
        /// <summary>
        /// Disconnect from the server.
        /// </summary>
        /// <param name="async">If true then async</param>
        public void Disconnect(bool async = false)
        {
            if (WSServer != null)
            {
                throw new Exception("Cannot both be a server and a client." +
                                    " Please use Disconnect if you are diconnecting from a server or StopListening to stop the server.");
            }

            if (WS == null)
            {
                return;
            }

            if (!WS.IsAlive)
            {
                return;
            }

            if (async)
            {
                WS.CloseAsync();
            }
            else
            {
                WS.Close();
            }

            DataSocket.Close();
        }
Ejemplo n.º 2
0
        public void Dispose()
        {
            if (WS != null && WS.IsAlive)
            {
                WS.Close();
            }
            if (WSServer != null && WSServer.IsListening)
            {
                WSServer.Stop();
            }

            if (DataSocket != null)
            {
                DataSocket.Close();
            }

            WS         = null;
            WSServer   = null;
            DataSocket = null;
            Serializer = null;
        }