您的位置:首页 > 理论基础 > 计算机网络

异步http listener 完全并发处理惩罚http恳求的小例子

2018-10-12 14:09 477 查看

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();

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

             sSocket.Start();

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

             Console.Read();           
         }

         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 { }

         }
     }
 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: