C# TcpListener 外部 IP [英] C# TcpListener external IP

查看:51
本文介绍了C# TcpListener 外部 IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 TcpListener,我希望来自其他计算机的客户端能够加入我的侦听器.

I'm creating a TcpListener, and I want clients from other computers to be able to join my listener.

我已经阅读并理解我必须进行端口转发,但这对我来说没有任何意义 - 当我发布我的应用程序时,我希望其他人创建这个监听器,我不能告诉他们进行端口转发.

I've read and understood that I have to do Port Forwarding, but it doesn't make any sense to me - when I publish my app, I want other people to create this Listener, and I can't tell them to do Port Forwarding.

是否有可能创建一个客户端无需端口转发即可加入的 TcpListener?谢谢你.

Is there any possibility to create a TcpListener that clients will be able to join without Port Forwarding? Thank you.

推荐答案

好吧,让我们先尝试清除一些东西.

Well, lets try to clear somethings out first.

使用端口转发的主要原因是您在内部网络前面有一个 NAT 路由器.设置端口转发是指示 NAT 路由器将流量转发到公共接口上的某个端口到内部计算机上的端口.

The main reason to use port forwarding is because you have a NAT router in front of an internal network. To setup a port forward is to instruct the NAT router to forward traffic to a certain port on the public interface to a port on an internal computer.

如果您没有 NAT 路由器,则不需要端口转发.

If you don't have a NAT router you don't need port forwarding.

如今许多路由器都支持 UPnP,这是一种请求路由器创建特定端口的技术向前.一个合适的库可能是 ManagedUPnP.

Many routers today support UPnP, a technique to kindly ask the router to create a specific port forward. A suitable library to use might be ManagedUPnP.

但是,您仍然需要弄清楚路由器的公共 IP 以及您打开的端口并将其与其他应用程序通信.

However you still need to figure out the public IP of the router and what port you have opened and communicate that to your other applications.

如果您的路由器不允许 UPnP 或存在其他防火墙规则,您将无法正确设置端口转发.

If your router does not allow UPnP or there are other fire wall rules in place you can not set up a port forwarding correctly.

这篇关于C# TcpListener 外部 IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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