C#使用HTTPListener异步实现HTTP服务端,请求执行两次 20
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSy...
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);
// 该方法是我要进行的操作
CommonMethod();
}
catch
{ }
}
}
} 展开
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);
// 该方法是我要进行的操作
CommonMethod();
}
catch
{ }
}
}
} 展开
2个回答
展开全部
你是执闹激行液宽袜2次CommonMethod()?那可以巧哪用for循环啊。
追问
不是,我只想一个请求执行一次,但是一个请求进来后却执行了两次后,才会停下来等待接收另一个请求
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |