NAT 后面到 NAT 后面的连接

发布于 2024-10-18 16:46:24 字数 512 浏览 9 评论 0原文

我遇到了一个有趣的问题。基本上我有 2 部手机都位于 NAT 后面。我想使用 UDP 在两个设备之间直接通信。

我知道如果我启动从手机到服务器的连接,那么我可以将数据从该连接推送回手机(即从接收消息的同一端口将其发送回接收消息的同一 IP 和端口) 。因此,我可以通过将两部手机连接到服务器来轻松地在两台设备之间进行通信。然后将数据发送到服务器并将其重新路由回手机。这绕过了我可能遇到的任何 NAT 穿越问题。

不过,我宁愿只使用服务器将两个设备指向对方,然后让它们直接通信。我该怎么做呢?不使用 uPnP 之类的东西是否可以?

任何帮助将不胜感激!

编辑:我找到了此文档http://www.brynosaurus.com /pub/net/p2pnat/ 看起来发夹翻译就是我所追求的,但它看起来并没有得到广泛支持。我想知道移动ISP对UPnP的支持有多好?

I've come across an interesting problem. Basically I have 2 mobile phones that are both behind NATs. I want to communicate directly between the 2 devices using UDP.

I know if I initiate a connection from the phones to a server then I can push data back down that connection to the phone (ie send it back from the same port that received the message to the same ip and port that it was received from). So I can easily communicate between the 2 devices by connecting both phones to the server. Then sending data to the server and having it re-routed back to the phones. This bypasses any NAT traversal issues I may come up against.

However I would rather just use the server to point the 2 devices at each other and then let them communicate directly. How would I go about doing this? Is it possible without using something like uPnP?

Any help would be much appreicated!

Edit: I found this document http://www.brynosaurus.com/pub/net/p2pnat/ It looks like hairpin translation is what I'm after but it doesn't look to be widely supported. I wonder how good mobile ISP's support for UPnP is?

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

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

发布评论

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

评论(2

姜生凉生 2024-10-25 16:46:24

您正在寻找的是 UDP 打洞,请参见 http://en.wikipedia.org/wiki/ UDP_hole_punching

基本思想很简单,您告诉每个端点要使用的端口,然后它们开始发送 udp 数据包。 NAT'ing 设备在看到第一个传出数据包时将设置一条遍历规则,然后来自另一端的下一次尝试将匹配该遍历规则。

What you're looking for is UDP hole punching, see e.g. http://en.wikipedia.org/wiki/UDP_hole_punching

The basic idea is simple, you tell each endpoint the ports to use, and they start sending udp packets. The NAT'ing devices will set up a traversal rule when they see the first outgoing packet, and then the next attempt from the other end will match this traversal rule.

一梦等七年七年为一梦 2024-10-25 16:46:24

您需要一个中介服务器,以便客户端可以知道他们在哪里。然后一个通过uPNP打开一个服务器,另一个连接到它。

You need a mediator server, so the clients can tell where they are. Then one opens a server by uPNP, and the other connects to it.

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