服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C/C++ - 异步http listener 完全并发处理惩罚http恳求的小例子

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

2020-12-06 15:48C语言教程网 C/C++

异步http listener 完全并发处理惩罚http恳求的小例子,需要的朋友可以参考一下

复制代码 代码如下:


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

         }
     }
 }

延伸 · 阅读

精彩推荐