Пример #1
0
        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);
        }
Пример #2
0
        private static async Task RunServer(Socket listen, X509Certificate2 cert, int messageSize)
        {
            while (true)
            {
                Socket accept = await listen.AcceptAsync();

                SpawnTask(async() =>
                {
                    Stream s = new NetworkStream(accept);
                    s        = await SslHelper.GetServerStream(s, cert);

                    var serverHandler = new ServerHandler(s, messageSize);
                    await serverHandler.Run();
                });
            }
        }
Пример #3
0
        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);
        }