2 qq 18505197 qq_18505197 于 2014.08.31 11:45 提问

C# Httplistener 外网无法连接

外网ip无法连接到Httplistener(已经端口映射),但是内网可以比如 192.168.1.101:8080。用nodejs可以从外网连接,不知道是怎么回事.

public TCHttp(string hostname)
{
HttpListener httpListener = new HttpListener();
httpListener.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
httpListener.Prefixes.Add("http://+:8080/");
httpListener.Start();
httpListener.BeginGetContext(GetContextCallback, httpListener);

return;
}
private void GetContextCallback(IAsyncResult ar)
{
HttpListener httpListener = ar.AsyncState as HttpListener;
HttpListenerContext listenerContext = httpListener.EndGetContext(ar);
httpListener.BeginGetContext(GetContextCallback, httpListener);
using (StreamWriter responseWriter = new StreamWriter(listenerContext.Response.OutputStream))
{
OnReceiveHttpContext(listenerContext, responseWriter);
responseWriter.Close();
}
listenerContext.Response.Close();
}

Csdn user default icon
上传中...
上传图片
插入图片