System.Net.HttpListener类(异步方式处理请求)
2010-04-07 09:17
357 查看
class program
{
static void Main()
{
System.Console.WriteLine(System.Net.HttpListener.IsSupported?"可用于本系统":"不可用于本系统");
System.Net.HttpListener httplistener = new System.Net.HttpListener();
string s = string.Format("http://localhost:8008/hello/");
httplistener.Prefixes.Add(s);
httplistener.Start();
while (true)
{
System.Console.Title = string.Format("0代收集{0}次 1代收集{1}次 2代收集{2}次",
System.GC.CollectionCount(0).ToString(),
System.GC.CollectionCount(1).ToString(),
System.GC.CollectionCount(2).ToString());
System.IAsyncResult ia2 = httplistener.BeginGetContext(
delegate(System.IAsyncResult ia)
{
System.Net.HttpListener httplistener2 = ia.AsyncState as System.Net.HttpListener;
System.Net.HttpListenerContext hlc = httplistener2.EndGetContext(ia);
hlc.Response.ContentType = "text.html";
System.IO.StreamWriter sw = new System.IO.StreamWriter(
hlc.Response.OutputStream,
System.Text.Encoding.Default
);
sw.WriteLine("你好, 中国");
sw.Flush();
sw.Close();
},
httplistener
);
//System.Threading.Thread.Sleep(1000);
}
}
}
{
static void Main()
{
System.Console.WriteLine(System.Net.HttpListener.IsSupported?"可用于本系统":"不可用于本系统");
System.Net.HttpListener httplistener = new System.Net.HttpListener();
string s = string.Format("http://localhost:8008/hello/");
httplistener.Prefixes.Add(s);
httplistener.Start();
while (true)
{
System.Console.Title = string.Format("0代收集{0}次 1代收集{1}次 2代收集{2}次",
System.GC.CollectionCount(0).ToString(),
System.GC.CollectionCount(1).ToString(),
System.GC.CollectionCount(2).ToString());
System.IAsyncResult ia2 = httplistener.BeginGetContext(
delegate(System.IAsyncResult ia)
{
System.Net.HttpListener httplistener2 = ia.AsyncState as System.Net.HttpListener;
System.Net.HttpListenerContext hlc = httplistener2.EndGetContext(ia);
hlc.Response.ContentType = "text.html";
System.IO.StreamWriter sw = new System.IO.StreamWriter(
hlc.Response.OutputStream,
System.Text.Encoding.Default
);
sw.WriteLine("你好, 中国");
sw.Flush();
sw.Close();
},
httplistener
);
//System.Threading.Thread.Sleep(1000);
}
}
}
相关文章推荐
- Asp.net错误“System.Web.HttpException: 超过了最大请求长度”解决办法
- 异步http listener 完全并发处理惩罚http恳求的小例子
- Java http处理get请求,参数中带特殊字符处理方式
- HTTP 通信, 三种方式XML 解析,并通过 Hander 实现异步消息处理
- Asp.Net构架(Http请求处理流程) - Part.1
- java中httpclent以post方式提交请求时,http返回码是302重定向时,不自动跳转的处理
- ASP.NET(IIS)出现"没有为请求类型"GET"找到 HTTP 处理程序"
- ASP.NET构架与安全机制之Http请求处理
- 【转】System.Net.HttpWebRequest请求超时的问题解决方法
- ASP.NET MVC 中如何用自定义 Handler 来处理来自 AJAX 请求的 HttpRequestValidationException 错误
- Asp.Net构架(Http请求处理流程) - Part.1
- angularjs $q、$http 处理多个异步请求
- System.Net.HttpClient Post 处理复杂类型
- python处理HTTP 请求的几种方式
- ASP.NET之自定义异步HTTP处理程序(图文教程)
- [转]Asp.Net构架(Http请求处理流程) - Part.1
- ASP.NET之自定义异步HTTP处理程序(图文教程)
- Asp.Net构架(Http请求处理流程)
- Asp.Net构架(Http请求处理流程)
- Asp.Net构架(Http请求处理流程) - Part.1