Esempio n. 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);
        }
Esempio n. 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();
                });
            }
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
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);
        }