public void Stop()
        {
            if (!Running)
            {
                Logger.DebugWrite("INFO", $"Tried stopping WebSocket Server but already stopped.");
                return;
            }

            foreach (var key in Users.Keys)
            {
                WebSocketUser user;

                if (Users.TryGetValue(key, out user))
                {
                    RemoveClient(user, WebSocketDisconnection.ServerShutdown);
                    user.ListenToken.Cancel();
                }
            }

            ListenToken.Cancel();
            RttToken?.Cancel();

            try {
                Socket.Shutdown(SocketShutdown.Both);
            } catch (Exception) {
            }

            Running = false;
        }
Beispiel #2
0
        public void Disconnect()
        {
            Running = false;

            ConnectToken?.Cancel();
            ListenToken?.Cancel();

            try {
                Socket.Shutdown(SocketShutdown.Both);
            } catch (Exception) {
            }
        }