zoukankan      html  css  js  c++  java
  • [Visual C#] 异步HttpListener 完全并发处理HTTP请求示例

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Net;
     6 using System.Net.Sockets;
     7 using DevSDK.Net.Sockets;
     8 using System.IO;
     9 
    10 namespace ConsoleApplication1
    11 {
    12     class Program
    13     {
    14         static HttpListener sSocket = null;
    15         
    16         static void Main(string[] args)
    17         {
    18             sSocket = new HttpListener();
    19 
    20             sSocket.Prefixes.Add("http://127.0.0.1:8080/");
    21 
    22             sSocket.Start();
    23 
    24             sSocket.BeginGetContext(new AsyncCallback(GetContextCallBack), sSocket);
    25 
    26             Console.Read();            
    27         }
    28 
    29         static void GetContextCallBack(IAsyncResult ar)
    30         {
    31             try
    32             {
    33                 sSocket = ar.AsyncState as HttpListener;
    34 
    35                 HttpListenerContext context = sSocket.EndGetContext(ar);
    36 
    37    sSocket.BeginGetContext(new AsyncCallback(GetContextCallBack), sSocket);
    38 
    39                 Console.WriteLine(context.Request.Url.PathAndQuery);
    40 
    41             }
    42             catch { }
    43             
    44         }
    45     }
    46 }
  • 相关阅读:
    解决IE8不兼容通过class名获取元素的方法
    移动端页面遇到过的各种坑
    强大的正则表达式
    弹性盒子布局
    vue环境搭建
    fullpage.js使用指南
    ES5原生api(1)
    双色球中奖率分析(python)
    使用python脚本的3D引擎Panda3d
    Python lambda介绍
  • 原文地址:https://www.cnblogs.com/briny/p/2382916.html
Copyright © 2011-2022 走看看