Exemplo n.º 1
0
        public void Start()
        {
            if (listener.IsListening)
            {
                return;
            }

            listener.Start();

            for (int i = 0; i < HandlerThread; i++)
            {
                listener.GetContextAsync().ContinueWith(ProcessRequestHandler);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// wait a new web request
 /// </summary>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public async Task <IHttpContextImpl> GetContextAsync(CancellationToken cancellationToken)
 {
     System.Net.HttpListenerContext context = null;
     try
     {
         context = await _listener.GetContextAsync().ConfigureAwait(false);
     }
     catch (OperationCanceledException e) when(cancellationToken.IsCancellationRequested)
     {
         Console.WriteLine(e.Message);
     }
     return(new SystemHttpContext(context, cancellationToken));
 }
Exemplo n.º 3
0
 private void fluxListener()
 {
     using (var httpListener = new System.Net.HttpListener())
     {
         httpListener.Prefixes.Add("http://localhost:8811/");
         httpListener.Prefixes.Add("http://127.0.0.1:8811/");
         try
         {
             httpListener.Start();
         }
         catch (Exception ex)
         {
             Logger.QueueException("Flux Error", ex);
             return;
         }
         while (!fluxListenerTerminate && Thread.CurrentThread.ThreadState == ThreadState.Background)
         {
             //var ctx = httpListener.GetContext();
             var tsk = httpListener.GetContextAsync();
             if (!tsk.Wait(500))
             {
                 continue;
             }
             var ctx = tsk.Result;
             if (ctx.Request.HttpMethod == "POST")
             {
                 var ct = ctx.Request.QueryString.Get("ct");
                 if (!string.IsNullOrWhiteSpace(ct))
                 {
                     ctx.Response.StatusCode = 200;
                     System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(
                         () => setColorTemp(colorTemp = int.Parse(ct)));
                     Logger.QueueLine("Color Temp Updated: {0}K", colorTemp);
                 }
                 else
                 {
                     ctx.Response.StatusCode = 404;
                 }
                 using (var strean = ctx.Response.OutputStream)
                 {
                 }
             }
         }
         Logger.QueueLine("Stopping f.lux listener");
         Task.WaitAll(Logger.FlushQueueAsync());
         httpListener.Stop();
     }
 }
Exemplo n.º 4
0
        private async void Listen()
        {
            this.WriteLogMethodName();
            while (true)
            {
                var context = await HttpListener.GetContextAsync();

                Console.WriteLine("Client connected");
                //Console.WriteLine(context.Request.AcceptTypes.ToString());

                WriteLog("Client Connected");
                WriteLog("Request Url: {0}", context.Request.Url);
                WriteLog("Request Url Absolute Path: {0}", context.Request.Url.AbsolutePath);
                WriteLog("Request Url Path and Query: {0}", context.Request.Url.PathAndQuery);
                WriteLog("Request UserAgent: {0}", context.Request.UserAgent);
                WriteLog("Request UserHostAddress: {0}", context.Request.UserHostAddress);
                WriteLog("Request UserHostName: {0}", context.Request.UserHostName);
                WriteLog("Request UserLanguages: {0}", context.Request.UserLanguages == null ? "" : string.Join(",", context.Request.UserLanguages));
                ProcessRequest(context);
            }

            HttpListener.Close();
        }