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 }
  • 相关阅读:
    把旧系统迁移到.Net Core 2.0 日记 (18) --JWT 认证(Json Web Token)
    把旧系统迁移到.Net Core 2.0 日记 (17) --多租户和SoftDelete
    swagger访问api, TypeError: Failed to fetch
    nop 4.1 Widget 探究- 视图组件
    Nop 4.1版本已经迁移到.net core2.1版本
    link标签和css引入方式
    script标签
    MIME 类型
    bae64编码
    chrome调试技巧和插件介绍
  • 原文地址:https://www.cnblogs.com/briny/p/2382916.html
Copyright © 2011-2022 走看看