コード例 #1
0
        private void AcceptCallback(IAsyncResult ar)
        {
            ClientConnection connection = new ClientConnection();
            connection.Socket = listener.EndAccept(ar);
            Receive(connection);

            blocker.Set(); // signal the loop to start listening for another connection.
        }
コード例 #2
0
 private void Receive(ClientConnection connection)
 {
     try
     {
         connection.Socket.BeginReceive(connection.Buffer, 0, ClientConnection.BufferSize, 0,
             new AsyncCallback(ReceiveCallback), connection);
     }
     catch (Exception ex)
     {
         Console.WriteLine("An error occured when attempting to receive from {0} : {1}", connection.UserName, ex.Message);
     }
 }