Exemplo n.º 1
0
        public async Task ServerLoop(SArbiter.CmdLineOptions options)
        {
            if (!HttpListener.IsSupported)
            {
                Console.WriteLine("HttpListener is not supported on this platform!");
                Environment.Exit(1);
            }

            using (HttpListener listener = new HttpListener())
                using (NetNode busMaster = new NetNode(listenPort: (int)options.BusPort))
                {
                    listener.Prefixes.Add(options.ApiUrl);

                    // Main server loop
                    listener.Start();
                    _updateTimer.Start();
                    Console.Error.WriteLine("Listening...");

                    bool keepGoing = true;
                    do
                    {
                        var task = await listener.GetContextAsync();

                        keepGoing = await ProcessRequest(task);
                    }while (keepGoing);

                    listener.Stop();
                    _updateTimer.Stop();
                    Console.Error.WriteLine("Stopped");
                }
        }
Exemplo n.º 2
0
        /// <summary>
        /// The entry point of the program.
        /// </summary>
        static async Task Main(string[] args)
        {
            SArbiter.CmdLineOptions options = null;
            Parser.Default.ParseArguments <SArbiter.CmdLineOptions>(args)
            .WithParsed <SArbiter.CmdLineOptions>((opts) => options = opts);
            if (options == null)
            {
                Environment.Exit(-1);
            }

            using (Program P = new Program(options))
            {
                await P.ServerLoop(options);
            }
        }