private static async Task <ClientHandler> StartOneAsync(EndPoint serverEndpoint, int messageSize) { Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); await client.ConnectAsync(serverEndpoint); Stream s = new NetworkStream(client); s = await SslHelper.GetClientStream(s); var clientHandler = new ClientHandler(s, messageSize); return(clientHandler); }
private static async Task <(ClientHandler clientHandler, ServerHandler serverHandler)> StartOneAsync(X509Certificate2 cert, int messageSize) { (var s1, var s2) = ProducerConsumerStream.Create(); var t1 = SslHelper.GetClientStream(s1); var t2 = SslHelper.GetServerStream(s2, cert); await Task.WhenAll(t1, t2); var clientHandler = new ClientHandler(t1.Result, messageSize); var serverHandler = new ServerHandler(t2.Result, messageSize); return(clientHandler, serverHandler); }
static void SslTest() { var cert = SslHelper.LoadCert(); Stream s1, s2; (s1, s2) = ProducerConsumerStream.Create(); Task <SslStream> t1 = SslHelper.GetClientStream(s1); Task <SslStream> t2 = SslHelper.GetServerStream(s2, cert); Task.WaitAll(t1, t2); s1 = t1.Result; s2 = t2.Result; Task.WaitAll(StreamTest.RunClient(s1), StreamTest.RunServer(s2)); }
private static async Task <(ClientHandler clientHandler, ServerHandler serverHandler)> StartOneAsync(X509Certificate2 cert, int messageSize) { // TODO: Use updated ProducerConsumerStream (Stream s1, Stream s2) = ProducerConsumerStream.Create(); // Note, this doesn't handle hangs properly and should be reworked if (cert != null) { var t1 = SslHelper.GetClientStream(s1); var t2 = SslHelper.GetServerStream(s2, cert); await Task.WhenAll(t1, t2); s1 = t1.Result; s2 = t2.Result; } var clientHandler = new ClientHandler(s1, messageSize); var serverHandler = new ServerHandler(s2, messageSize); return(clientHandler, serverHandler); }