异步httplistener完全并发处理惩罚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{}
}
}
}