예제 #1
0
 /// <summary>
 /// Callback event for the async listening method. (from main loop)
 /// If the server is not full then it
 /// sends the client the proper handshake sequence and then starts a clientReader thread.
 /// </summary>
 /// <param name="ar"></param>
 public void Client_Accepted(IAsyncResult ar)
 {
     this.listening.Set(); //start listening for a new client on the main thread
     TcpClient clientSocket = ((TcpListener)ar.AsyncState).EndAcceptTcpClient(ar);
     Client client = new Client(clientSocket);
     //subscribe to published events
     client.On_Client_Received += this.Client_Received;
     client.On_Client_Connected += this.Client_Connected;
     client.On_Client_Disconnected += this.Client_Disconnected;
     client.AuthorizeAndConnect("Guest_" + Interlocked.Increment(ref this.guestNumber));
 }