亲宝软件园·资讯

展开

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

人气:0
想了解异步http listener 完全并发处理惩罚http恳求的小例子的相关内容吗,在本文为您仔细讲解异步http listener 的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:http,listener,并发,下面大家一起来学习吧。
复制代码 代码如下:

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

         }
     }
 }

加载全部内容

相关教程
猜你喜欢
用户评论