如何连接两台不同子网的计算机?例如,假设如下:
192.168.1.92 连接到外部可见的 222.251.155.20。
192.168.1.102 连接到外部可见的 223.251.156.23。
现在两台机器都连接到中间人服务器,这样它们就可以协商彼此的内部和外部 IP,并让其中一个打开侦听端口。我目前知道如何做到这一点的唯一方法是端口转发。
我相当精通 C# 套接字,只是不知道如何连接位于两个不同子网上的两台计算机。
我有一个客户端连接到的服务器,该服务器有一个域名,通常客户端将位于家庭路由器后面,我希望它们能够直接相互共享信息。
How do I connect 2 different subnet’ed computers? For example sake let’s say the following:
192.168.1.92 connected to externally visible 222.251.155.20.
192.168.1.102 connected to externally visible 223.251.156.23.
Now there is middle man server that both machines are connected to so they can negotiate each other’s internal and external IP’s and have one open up a listening port. The only way I currently know how to do this is port forwarding.
I’m fairly proficient with C# sockets, just don’t how to connect two computers that are on two different subnets.
I have a server that the clients connect to that has a domain name, usally the clients will be behind home routers and I want them to be able to share information directly with each other.
发布评论
评论(1)
您要寻找的是NAT 穿越。
没有中继服务器和端口转发的解决方案通常使用某种形式的 UDP 打洞。
标准化机制是 STUN (即 STUN) org/wiki/Interactive_Connectivity_Establishment" rel="nofollow noreferrer">交互式连接建立)。
注意:通过 UDP 实现 UDP 打洞和可靠的文件传输并非易事。最好的选择可能是使用 UPnP 或 NAT-PMP 自动设置端口转发。两者都有库,例如 Mono.Nat (来源):
What you're looking for is NAT traversal.
Solutions without a relaying server and without port forwarding usually use some form of UDP hole punching.
A standardized mechanism is STUN (i.e. Interactive Connectivity Establishment).
Note: implementing UDP hole punching and reliable file transfer over UDP is not trivial. The best option is probably to automatically set up port forwarding with UPnP or NAT-PMP. There are libraries for both, e.g., Mono.Nat (sources):