public void Listen() { _server.Start(); while (true) { Console.Write("Waiting for a connection... "); _client = _server.AcceptTcpClient(); Console.WriteLine("Connected!"); try { while (_client.Connected) { NetworkStream stream = _client.GetStream(); var requestHeaders = ReadRequestHeaders(stream); ICommandHandler handler = _handlerFactory.SelectHandler(requestHeaders.CommandType); handler.Handle(stream, requestHeaders, _client); } } catch (SocketException e) { Console.WriteLine("SocketException: {0}", e); } } }