Пример #1
0
        private void OnClientConnected(ClientConnectedEventArgs e)
        {
            ClientConnectedEventHandler handler = this.ClientConnected;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Пример #2
0
        private void HandleConnections()
        {
            while (true)
            {
                TcpClient tcpClient = tcpListener.AcceptTcpClient();

                var clientConnectedEventArgs = new ClientConnectedEventArgs { TcpClient = tcpClient };

                //Thread clientThread = new Thread(() => OnClientConnected(clientConnectedEventArgs));
                //clientThread.Name = "Server_clientThread";
                //clientThread.Start();

                Task.Run(() => OnClientConnected(clientConnectedEventArgs));
            }
        }
Пример #3
0
        static void ServerClientConnected(object sender, ClientConnectedEventArgs e)
        {
            Console.WriteLine("Client accepted from {0}", e.TcpClient.Client.RemoteEndPoint);

            using (var user = new User(e.TcpClient.Client))
            {
                do
                {
                    user.ProcessRequest();
                }
                while (user.Status != User.UserStatus.Loggedout);

                Console.WriteLine("{0} is disconnected.", user.Name);
            }
        }