An asynchronous HTTP listener completely concurrently handles a small example of punishing an HTTP request

  • 2020-04-01 23:43:37
  • OfStack


using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Net;
 using System.Net.Sockets;
 using DevSDK.Net.Sockets;
 using System.IO;

 namespace ConsoleApplication1
 {
     class Program
     {
         static HttpListener sSocket = null;

         static void Main ( string[] args ) 
         {
             sSocket = new HttpListener (a) ;

             sSocket.Prefixes.Add ( "http://127.0.0.1:8080/" ) ;

             sSocket.Start (a) ;

             sSocket.BeginGetContext ( new AsyncCallback ( GetContextCallBack ),  sSocket ) ;

             Console.Read (a) ;            
         }

         static void GetContextCallBack ( IAsyncResult ar ) 
         {
             try
             {
                 sSocket = ar.AsyncState as HttpListener;

                 HttpListenerContext context = sSocket.EndGetContext ( ar ) ;

    sSocket.BeginGetContext ( new AsyncCallback ( GetContextCallBack ),  sSocket ) ;

                 Console.WriteLine ( context.Request.Url.PathAndQuery ) ;

             }
             catch { }

         }
     }
 }

Related articles: