你的分享就是我们的动力 ---﹥

[Visual C#] 异步HttpListener 完全并发处理惩罚HTTP恳求示例

时间:2013-05-24 15:10来源:www.chengxuyuans.com 点击:

名人名言:过分冷静的思考缺乏感情的冲动,也必然使人的心理变态。——瓦西列夫


1usingSystem;
2usingSystem.Collections.Generic;
3usingSystem.Linq;
4usingSystem.Text;
5usingSystem.Net;
6usingSystem.Net.Sockets;
7usingDevSDK.Net.Sockets;
8usingSystem.IO;
9
10namespaceConsoleApplication1
11{
12classProgram
13{
14staticHttpListenersSocket=null;
15
16staticvoidMain(string[]args)
17{
18sSocket=newHttpListener();
19
20sSocket.Prefixes.Add("http://127.0.0.1:8080/");
21
22sSocket.Start();
23
24sSocket.BeginGetContext(newAsyncCallback(GetContextCallBack),sSocket);
25
26Console.Read();
27}
28
29staticvoidGetContextCallBack(IAsyncResultar)
30{
31try
32{
33sSocket=ar.AsyncStateasHttpListener;
34
35HttpListenerContextcontext=sSocket.EndGetContext(ar);
36
37sSocket.BeginGetContext(newAsyncCallback(GetContextCallBack),sSocket);
38
39Console.WriteLine(context.Request.Url.PathAndQuery);
40
41}
42catch{}
43
44}
45}
46}
 


 

转载注明地址:http://www.chengxuyuans.com/Visual Studio/61969.html

推荐文章