UDP打孔帮助UDP

2023-09-04 02:00:02 作者:心已死、勿扰

我想在互联网上添加网络到我的比赛,用对等。 我已经实现了一个局域网的唯一版本,它使用.NET的点对点类本地网络内连接。

I'm trying to add networking over the internet to my game, using Peer to Peer. I have already implemented a LAN only version, which uses .NET's peer to peer classes to connect within the local network.

我意识到我需要使用UDP打孔,以建立与其他客户端在防火墙后面的连接。

I realized I need to use UDP hole punching in order to establish a connection to other clients that are behind a firewall.

这就是我已经开始实现它: 服务器是使用非常简单的PHP脚本来完成这项工作一个HTTP服务器。

This is how I have started to implement it: The server is a HTTP server using very simple PHP scripts to get the job done.

在服务器中注册的名称,将私有IP地址和端口作为一个GET变量 当服务器收到的注册请求,这将节省公共端点和私营端点 register name on server, sending the private ip address and port as a GET variable when the server gets a registration request, it will save the public endpoint and the private endpoint 请求连接到另一个客户端。 服务器将返回客户端的私人和公共端点 在每两秒钟,第二个客户端将检查与服务器,如果有另一个客户端试图与它连接,它会得到它的端点太 在这两个客户端开始发送垃圾邮件每个人的公共端点,直到他们得到一个有效的响应

现在我有一大堆的问题

的服务器可以是HTTP服务器? 当我提出一个请求到HTTP服务器,客户端发出请求每次变化。是一家民营端点总是匹配相同的公共端点? 是否请求到服务器必须具有相同的源端点作为UDP消息到客户端? 有没有一种方法使用指定的源端点连接到在C#中的HTTP服务器? 是否有我的执行情况的任何问题?

谢谢!

推荐答案

打洞是一个复杂的话题,许多曾尝试找到一个解决方案,工程。问题是,有这么多不同的NAT路由器在那里,并没有实施NAT的标准方式,因此所有的路由器的行为有点不同。

UDP hole punching is a complex topic, and many attempts have been made to find a solution that works. The problem is that there are so many different NAT routers out there, and there is no standard way of implementing NAT, so all routers behave a bit different.

一些尝试已经标准化,例如 STUN ,的 ICE 。他们仍然在大多数情况下,不是所有的只有工作,但他们积累了很多知识和解决的许多问题 - 比你尝试将以往任何时候都可以,只是因为你不能在阳光下每一个NAT路由器测试解决方案。 Skype为例,花了完善的NAT穿越机制的历史了。

Some attempts have been standardized, e.g. STUN, ICE. They still work only in most cases, not all, but they accumulate a lot of knowledge and address many concerns -- more than your attempt will ever be able to, simply because you can't test your solution with every NAT router under the sun. Skype, for example, spent years of perfecting its NAT traversal mechanism.

我建议你看看 STUN 或preferably ICE 。尝试实现其中之一或寻找已有的实现。

I recommend you have a look at STUN or preferably ICE. Try to implement one of them or look for existing implementations.

另一种选择可能是简单地在路由器,例如前锋创建端口使用的UPnP 或 NAT-PMP

Another option might be to simply create a port forward at the router, e.g. using UPnP or NAT-PMP.

这是说,我也不会感到惊讶,如果.NET点对点类想出了一个NAT穿越机制,但我不熟悉他们。

That said, I wouldn't be surprised if the .NET peer to peer classes came with a NAT traversal mechanism, but I'm not familiar with them.