示例#1
0
文件: Server.cs 项目: hakan648/Gap
        private void OnClientConnected(ClientConnectedEventArgs e)
        {
            ClientConnectedEventHandler handler = this.ClientConnected;

            if (handler != null)
            {
                handler(this, e);
            }
        }
示例#2
0
文件: Server.cs 项目: hakan648/Gap
        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
文件: Program.cs 项目: hakan648/Gap
        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);
            }
        }