外网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();
}
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();
}