如何在HttpListener中使用我的公共IP [英] how to use my public IP with HttpListener

查看:101
本文介绍了如何在HttpListener中使用我的公共IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我已经知道了...

I've got this so far...

public static HttpListener listener = new HttpListener();
public static string startUpPath = Application.StartupPath;
public  WebServer()
{
    listener.Start();

    listener.Prefixes.Add("http://(here I want my public ip)/");
    Thread t = new Thread(new ThreadStart(clientListener));
    t.Start();
}

但是当我初始化类时,它说指定的网络格式无效"

But when I initialize the class it says "The specified Network format is not valid"

因为我的视觉工作室语言是西班牙语,所以翻译可能并不完美.我的IP看起来像95.^^.^^^.^^,我认为这可能是问题所在,因为当我使用本地IP时它可以工作.

The translation may not be perfect because my visual studio language is in Spanish. My ip looks like 95.^^.^^^.^^ and I think that may be the problem because it works when I use my local ip.

//已编辑

确切的例外是:红色的电子格式的规范"指定的网络名称无效".如果我添加前缀"http://+:80/" 它仍在继续,但是如何通过我的公共IP访问它?

The exact exception is: "El formato del nombre de red especificado no es válido" Which is"The specified network name is not valid". If I add the prefix "http:// + :80/" it still going, but how can I access that through my public ip?

推荐答案

设置时,您应该使用内部IP,因为这是您正在监听的实际IP.为了从您的外部IP获取流量,您需要将该流量从路由器转发到正在侦听其内部IP的计算机.

When setting this up you should use your internal IP, since that is the actual IP you are listening on. In-order to get traffic from the your external IP, you need to forward that traffic from your router to your computer that is listening on its internal IP.

一种设置方法是使用路由器的端口转发,您希望将端口80上传入的所有流量定向到您的计算机.

One way to set it up is to use port forwarding, from your router, you would want to direct any traffic that comes in on port 80 to your computer.

更多信息: http://en.wikipedia.org/wiki/Port_forwarding

这篇关于如何在HttpListener中使用我的公共IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆