需要 udp 打孔帮助

发布于 2024-10-18 17:28:08 字数 139 浏览 2 评论 0原文

嘿,我正在开发一个用 java 创建 p2p 网络的项目。 我已经使用 UDP 为本地 LAN 构建了 n/w,并且我正在研究 通过 Internet 发送 UDP 数据报。我遇到了这个称为 UDP 打洞的概念,但似乎找不到任何相关的主题或库。 有人可以帮忙吗?

Hey I'am working on a project to create a p2p network in java.
I have built the n/w using UDP for the local lan and I am working on
sending the UDP datagram across the internet. I came across this concept called UDP hole punching but cannot seem to find any relevant topic or libraries.
Can anyone please help?

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

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

发布评论

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

评论(5

酒浓于脸红 2024-10-25 17:28:08

我认为这就是通常所说的NAT 穿透。也许你用这个标题搜索会更幸运。

I think this is what is often called NAT punch-through. Maybe you'll have more luck searching with that title.

滥情空心 2024-10-25 17:28:08

以下是一些强烈推荐的 UDP(或 TCP)打洞技术材料:

http://www.usenix.org/events/usenix05/tech/general/full_papers/ford/ford_html/

或者,当然,维基百科:

http://en.wikipedia.org/wiki/UDP_hole_punching

本质上,由于大多数计算机都位于所谓的网络地址转换器 (NAT) 后面,因此您需要使用计算机的公共 IP 和公共端口,就像互联网上的人看到的那样。另外,您将需要私有 IP 和私有端口(或者当应用程序本身看到它的套接字时......这只是为了防止您与您尝试连接的其他应用程序/计算机/节点位于相同的 NAT 后面)。然后两个节点都尝试通过尝试公共和私有地址来建立连接。当这两个应用程序建立联系时,它们就成功地穿越了 NAT——它们已经成功打洞了。

一种流行的方法是让两个客户端都连接到有助于协调两个客户端的服务器。它协调将公共和私有 IP 以及端口发送到其他客户端,然后它们使用这些客户端来执行“打孔”。

此外,显然使用 UDP 协议是因为它比 TCP 更(根据经验)成功。注意:我试图找到这方面的统计数据,但没有成功。

Here is some highly recommended technical material for UDP (or TCP) hole punching:

http://www.usenix.org/events/usenix05/tech/general/full_papers/ford/ford_html/

Or, of course, wikipedia:

http://en.wikipedia.org/wiki/UDP_hole_punching

Essentially, since most computers are behind what are called Network Address Translators (NAT), you will need to use the computers public IP and public port as someone on the internet sees them. Also, you will need the private IP and private port (or as the application itself sees its sockets... this is just in case you are behind the same NAT as the other application/computer/node you are trying to connect to). Then BOTH the two nodes try and establish a connection by trying the public and private addresses. When these two applications establish contact, they have successfully traversed the NAT--they have successfully hole-punched.

A popular way of doing this is to have both clients connect to a server which helps coordinate the two clients. It coordinates the sending of the public and private IP's and ports to the other client, which they then use to perform the "hole punch."

Also, apparently UDP protocol is used because it is more (empirically) successful than TCP. Note: I tried to find the statistics on that but was unsuccessful.

姐不稀罕 2024-10-25 17:28:08

您不能通过 inetrnet 进行 UDP 广播/多播。然而,您可以通过互联网传递 TCP。

我建议您尝试让网络上的网关侦听您选择的 UDP 数据包,通过 TCP 将数据传递到另一个网络上的另一个网关,后者可以将此信息转换回 UDP。

You cannot do UDP broadcast/multi-cast over the inetrnet. You can however pass TCP over the internet.

What I suggest you try is to have a gateway on your network listen to UDP packets of your choice, pass the data over TCP to another gateway on the other network which can turn this information back into UDP.

逆流 2024-10-25 17:28:08

您可能正在寻找 uPnP 的 NAT 穿越工具。许多消费者路由器支持以编程方式打开整个防火墙并为任何类型的应用程序请求转发端口。或者蠕虫。无论哪种方式。 :)

You're probably looking for uPnP's NAT traversal facility. Many consumer routers support programmatically opening up the entire firewall and forwarding ports for any kind application that asks. Or worm. Either way. :)

云归处 2024-10-25 17:28:08

查看有关NAT 到 NAT 遍历的其他问题。 Erik 对 UDP 打洞有很好的描述。

Check out this other question on NAT-to-NAT traversal. Erik has a nice description of UDP hole punching.

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