Esempio n. 1
0
        public void TestConnectWithSsl()
        {
            ObjectPool <byte[]> pool = new ObjectPool <byte[]>(() => { return(new byte[1024]); });

            string           text   = "some great text here...";
            HttpSimpleServer server = new HttpSimpleServer(pool);

            try
            {
                server.Start(true, text);

                BlockingCollection <object> blockingCollection = new BlockingCollection <object>();

                ClientSockNetChannel client = (ClientSockNetChannel)SockNetClient.Create(server.Endpoint, ClientSockNetChannel.DefaultNoDelay, ClientSockNetChannel.DefaultTtl, pool)
                                              .AddModule(new HttpSockNetChannelModule(HttpSockNetChannelModule.ParsingMode.Client));

                client.ConnectWithTLS((object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => { return(true); })
                .WaitForValue(TimeSpan.FromSeconds(5));

                object currentObject;

                client.Pipe.AddIncomingLast <HttpResponse>((ISockNetChannel sockNetClient, ref HttpResponse data) => { blockingCollection.Add(data); });

                client.Send(new HttpRequest(client.BufferPool)
                {
                    Action = "GET", Path = "/", Version = "HTTP/1.0"
                });

                Assert.IsTrue(blockingCollection.TryTake(out currentObject, DEFAULT_ASYNC_TIMEOUT));

                Assert.IsTrue(currentObject is HttpResponse);

                Console.WriteLine("Got " + currentObject.GetType() + ": \n" + currentObject);

                client.Disconnect().WaitForValue(TimeSpan.FromSeconds(5));
            }
            finally
            {
                server.Stop();
            }
        }