예제 #1
0
        static void Main()
        {
            var eventLoop = new EventLoopScheduler();

            using (var requests = new HttpServer("http://127.0.0.1:987/", eventLoop))
            {
                requests.GET("app.js")
                    .Subscribe(r => r.Respond(new StaticFileResponse("app.js")));

                requests.GET("index.html")
                    .Subscribe(r => r.Respond(new StaticFileResponse("index.html")));

                var messageStream = requests.POST("send")
                    .Select(r => {
                              string message;
                              using(var sr = new StreamReader(r.Request.InputStream))
                              {
                                  message = sr.ReadToEnd();
                              }
                              r.Respond(201);
                              return message;
                    }).Publish().RefCount();

                requests.POST("wait")
                        .SelectMany(subscriber => messageStream.Take(1),
                                   (subscriber, message) => new {subscriber, message})
                        .Subscribe(kp => kp.subscriber.Respond(new StringResponse(kp.message)));

                Console.ReadLine();
            }
        }
예제 #2
0
        private void RegisterRequestHandlers(Anna.HttpServer httpd)
        {
            httpd.GET(CrossDomainPath).Subscribe(context =>
            {
                context.Respond(CrossDomainText);
            });

            httpd.POST(JsonRpcPath).Subscribe(context =>
            {
                var repData = this.HandleJsonRpcRequest(context.Request);
                context.Response(repData, 200).Send();
            });
        }
예제 #3
0
        public void Start(Action waitingBlocker)
        {
            LoggerProvider.EnvironmentLogger.Info(
                String.Format("Starting the HTTP Server [{0}]...", this._httpHostUri));

            using (var eventLoop = new EventLoopScheduler())
                using (var httpd = new Anna.HttpServer(this._httpHostUri, eventLoop))
                {
                    this.RegisterRequestHandlers(httpd);
                    waitingBlocker();
                }

            LoggerProvider.EnvironmentLogger.Info("The HTTP server is stopped.");
        }
예제 #4
0
        public void Start()
        {
            Debug.Assert(this.senderSocket != null);

            this.senderSocket.Connect(this.rpcReqUrl);

            LoggerProvider.EnvironmentLogger.Info(
                String.Format("Starting the HTTP Server [{0}]...", this.httpHostUrl));

            using (var httpd = new Anna.HttpServer(this.httpHostUrl))
            {
                this.RegisterRequestHandlers(httpd);

                this.WaitForStopCommand();
            }

            LoggerProvider.EnvironmentLogger.Info("The HTTP server is stopped.");
        }