zl程序教程

您现在的位置是:首页 >  大数据

当前栏目

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

并发异步HTTP 处理 例子 完全 惩罚
2023-06-13 09:14:59 时间
复制代码代码如下:

usingSystem;
 usingSystem.Collections.Generic;
 usingSystem.Linq;
 usingSystem.Text;
 usingSystem.Net;
 usingSystem.Net.Sockets;
 usingDevSDK.Net.Sockets;
 usingSystem.IO;

 namespaceConsoleApplication1
 {
    classProgram
    {
        staticHttpListenersSocket=null;

        staticvoidMain(string[]args)
        {
            sSocket=newHttpListener();

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

            sSocket.Start();

            sSocket.BeginGetContext(newAsyncCallback(GetContextCallBack),sSocket);

            Console.Read();           
        }

        staticvoidGetContextCallBack(IAsyncResultar)
        {
            try
            {
                sSocket=ar.AsyncStateasHttpListener;

                HttpListenerContextcontext=sSocket.EndGetContext(ar);

   sSocket.BeginGetContext(newAsyncCallback(GetContextCallBack),sSocket);

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

            }
            catch{}

        }
    }
 }