通过广域网通信

发布于 2024-09-17 05:03:24 字数 225 浏览 7 评论 0原文

我想用 C# 创建应用程序客户端服务器,但不仅仅在 LAN 中。这很简单:TcpListener、TcpClient 等。

我想像这样做一些事情,例如 我的计算机上有正在等待连接的服务器。 另一个网络中的某个人有客户端。他开始连接,但是...服务器的IP在哪里? 他只看到路由器的IP。

有什么想法吗? :)

编辑

大问题也是双 NAT

I want to create app client-server in C# but not only in LAN. There it's easy: TcpListener, TcpClient etc.

I want to make sth like in this e.g.
On my comp is server that's waiting for a connection.
Someone in another network has client. He begin connection, but...where...what is a IP of server?
He see only ip of router.

Any ideas? :)

EDIT

Big problem is also double-NAT

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

抚笙 2024-09-24 05:03:24

您仍然使用相同的 TcpListener 和 TcpClient(如果您想将其设置为低级别)。

通过 WAN 进行通信的技术与通过 LAN 进行通信的技术相同。困难的部分是在客户端和服务器之间建立网络,以允许您使用必要的端口和协议。

You still use the same TcpListener and TcpClient (if you want to make it that low level).

The technologies for communicating over a WAN are the same for communicating over a LAN. The difficult part is getting the networks in between the client and server to allow you to use the necessary ports and protocols.

萌能量女王 2024-09-24 05:03:24

你的问题并不能解释整个场景..但根据我对问题的理解,我可以建议以下答案:
根据目标客户群的位置(是否支持企业网络),您可以使用各种路由选项,例如 UPnPSTUNTIPv6,或者其他一些NAT穿越选项,这样你就可以通知客户端监听器在哪里是。应该始终有一个中央注册服务器,侦听器将向该服务器通知其所在位置以及其环境中允许的通信模式。对于此类目的,使用 XMPP 服务器是一个简单的选择,它可以解决大多数此类问题。一旦客户端从发现服务器查询到监听器的位置,就可以直接连接到监听器。

You question doesn't explain the whole scenario.. but with my understanding of the problem I can suggest the following answer:
Depending on the Target customer base's locations (support for Corporate networks or NOT), you can use various routing options like UPnP, STUNT or IPv6, or some other NAT traversal options, so that you can inform the client about where the listener is. There should always be a central registry server to which the Listener would inform its whereabouts and the mode of the communications permitted in its environments. Use of an XMPP server would be an easy option for such purposes, which solves most of such issues. Once the client queries about the location of the listener from the discovery server, it can directly connect to the Listener.

疯狂的代价 2024-09-24 05:03:24

听起来您只想在路由器上设置端口转发。当在客户端连接的特定端口上建立传入连接时,路由器应将连接重定向到您在 LAN 上指定的计算机。 (通常是像 192.168.xx 这样的 IP)。这也应该是您的 TcpListener 正在侦听连接的 IP 地址。

如果您需要针对特定​​路由器进行设置的帮助,可以尝试 portforward.com

Sounds like you just want to set up port forwarding on your router. When an incoming connection is made on the specific port a client connects to, the router should redirect the connection to the machine you specify on the LAN. (Usually an IP like 192.168.x.x). This should also be the IP address your TcpListener is listening for connections on.

You can try portforward.com if you need help setting it up for a particular router.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文