private void ConnectToServer(string hostName, int port) { try { var connection = TcpClientConnectionFactory.Build(hostName, port); _continuousRequestProcessor.StartProcessingRequestFromConnection(connection); _clientInformation.CurrentConnection = connection; } catch (ConnectionException) { throw new ClientException(string.Format("Unable to connect to the host '{0}' on the port '{1}'.", hostName, port)); } }
public void GivenAConnectionIsEstablishedBetweenServerAndClientOnPort(int port) { var serverTask = Task.Run <IConnection>(() => { var listener = new TcpListener(IPAddress.Any, port); listener.Start(); var client = listener.AcceptTcpClient(); listener.Stop(); return(new TcpClientConnection(client)); }); var clientTask = Task.Run(() => TcpClientConnectionFactory.Build("localhost", port, 50)); Task.WaitAll(serverTask, clientTask); ServerConnection = serverTask.Result; ClientConnection = clientTask.Result; }