public void HttpSocket3TimeNativeSocket(int count)
        {
            var ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 50651);

            var req = new HttpRequest {
                Uri = new Uri("http://127.0.0.1:50651/x2.html")
            };
            var reader = new HttpResponseReader();
            var sw     = Stopwatch.StartNew();

            for (var i = 0; i < count; i++)
            {
                HttpResponse r;
                using (var socket = new Socket(SocketType.Stream, ProtocolType.Tcp)){
                    socket.Connect(ep);
                    using (var s = new NetworkStream(socket)){
                        var w = new HttpRequestWriter(s);
                        w.Write(req);
                        r = reader.Read(s);
                    }
                    Assert.Greater(r.StringData.Length, 10);
                }
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed);
        }
Beispiel #2
0
        string Execute(HttpRequest request)
        {
            var ms  = new MemoryStream();
            var hrw = new HttpRequestWriter(ms);

            hrw.Write(request);
            var size = ms.Position;

            ms.Position = 0;
            var buffer = new byte[size];

            ms.Read(buffer, 0, (int)size);
            return(Encoding.UTF8.GetString(buffer));
        }