예제 #1
0
        public void Start()
        {
            try
            {
                listener = new TcpListener(IPAddress.Parse("127.0.0.1"), port);
                listener.Start();

                Console.WriteLine("Server is ready to get connections\n");

                while (true)
                {
                    TcpClient client = listener.AcceptTcpClient();

                    WebSocketsClient clientObj = new WebSocketsClient(this, client, Id++);

                    Clients.Add(clientObj);

                    Thread clientThread = new Thread(new ThreadStart(clientObj.Process));
                    clientThread.Start();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error in Server.Start():" + ex.Message);
            }
            finally
            {
                if (listener != null)
                {
                    listener.Stop();
                }
            }
        }
예제 #2
0
        public void RemoveUser(WebSocketsClient user)
        {
            Clients.Remove(user);
            ConsoleLogger.Write($"{user.Nickname} deleted from server collection");

            user.Client.GetStream().Close();
        }