示例#1
0
 private void HandleAsyncConnection(IAsyncResult res)
 {
     try {
         using (var tcpClient = _listener.EndAcceptTcpClient(res)) {
             StartAccept();
             Trace.TraceInformation("Connection opened");
             using (var networkStream = tcpClient.GetStream()) {
                 var connectionDetails = GetConnectionDetails(networkStream, tcpClient);
                 using (var connection = _connectionFactory.CreateInstance(connectionDetails)) {
                     try {
                         lock (_openConnections) {
                             _openConnections.Add(connection);
                         }
                         connection.Respond();
                     }
                     finally {
                         lock (_openConnections) {
                             _openConnections.Remove(connection);
                         }
                     }
                 }
             }
             Trace.TraceInformation("Connection closed");
         }
     }
     catch (ObjectDisposedException) {
     }
     catch (Exception ex) {
         Trace.TraceError(ex.ToString());
     }
 }