예제 #1
0
        public void HelloWorld()
        {
            const string address     = "http://localhost:8080/";
            var          contextsHot = HttpObservable.GetContexts(address);
            int          count       = 0;
            const int    expected    = 2;

            try
            {
                var contexts = contextsHot.Publish();
                contexts.Subscribe(RespondWithHelloWorld);
                contexts.Subscribe(_ => Interlocked.Increment(ref count));
                var waiter = contexts.ToTask();
                contexts.Connect();

                for (int i = 0; i < expected; i++)
                {
                    GetRequest(address);
                }

                contextsHot.Dispose();
                waiter.Wait(TimeSpan.FromSeconds(2));
            }
            finally
            {
                contextsHot.Dispose();
            }

            Assert.AreEqual(expected, count);
        }
예제 #2
0
        public HttpListenerServer(string prefix)
        {
            _contexts = HttpObservable.GetContexts(prefix);
            const string responseString = "<HTML><BODY> Hello world!</BODY></HTML>";

            _buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
            Console.WriteLine("Listening on " + prefix);
        }
예제 #3
0
        public static void Main(string args)
        {
            var contexts = HttpObservable.GetContexts("http://+:8080/");

            contexts.Subscribe(async context =>
            {
                var response             = context.Response;
                var buffer               = Encoding.UTF8.GetBytes("<HTML><BODY> Hello world!</BODY></HTML>");
                response.ContentLength64 = buffer.Length;
                await response.OutputStream.WriteAsync(buffer, 0, buffer.Length);
                response.OutputStream.Close();
            });

            Console.ReadKey();
            contexts.Dispose();
        }