UDP、NAT 和建立“连接" [英] UDP, NAT and setting up "connections"

查看:17
本文介绍了UDP、NAT 和建立“连接"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道连接"这个词在谈论 UDP 时并不合适,但是...

I know the word "connection" isn't really appropriate when talking about UDP, but...

服务器(具有已知 IP 的服务器)如​​何通过 Internet 将其 UDP 数据包发送到位于 NAT 后面的客户端?

How does a server (the one with the known IP) get its UDP packets through the Internet to a client that is behind NAT?

例如:假设客户端使用 TCP 上的一些消息连接并验证服务器.此时,服务器已准备好开始通过 UDP 将数据流式传输到客户端,但服务器如何知道将 UDP 数据包寻址到何处,以便它们可以通过任何 NAT 路由器到达客户端?

For example: say a client connects and authenticates to the server using some messaging over TCP. At this point the server is ready to start streaming data to the client over UDP, but how does the server know where to address the UDP packets so that they would find their way through any NAT routers to the client?

如果客户端通过 UDP 发送我已准备好进行流式传输"消息,NAT 路由器是否会保持端口打开,以便服务器可以使用其 UDP 数据流进行响应?

If the client fist sends an "I'm ready for the streaming please" message over UDP, would the NAT routers keep the port open so that the server can respond with its stream of UDP data?

或者我在这里偏离了轨道?

Or am I waay off track here?

推荐答案

一般情况下,TCP 层的客户端前面的 NAT 将能够确定创建了 UDP 的连接.话虽如此,客户端的 NAT 必须配置为接受来自 SRC 服务器端口的 UDP 数据包,然后将它们转发到内部目标 IP(客户端).如果 NAT 是谁是呼叫者,谁是被呼叫者,请记住重要的事情.NAT 在实施和能力方面有所不同,因此您可能想要实施一个易于实施的通用解决方案,具体取决于您的需要.

Generally the NAT in front of the client at the TCP level will be able to determine that the connection at the UDP was create. Having said that, the NAT on the client side will have to be configured to accept UDP packets from the SRC server port, and then forward them to the internal destination IP (client). Important thing to remember if NAT is who is the caller and who is the callee. NATs differ in implementation and capablity so a generic easy to implement solution is probably what you might want to implement, depending on your needs.

我认为,您的假设是正确的,在您的情况下,客户端将无法接收信息中的 UDP 流.在您的情况下,您的客户端必须将其 WAN IP 发送到您的服务器以启动 UDP 连接.查找您的客户 WAN IP 可能很棘手,但有些网站可以通过在文本页面中返回来帮助您确定您的 WAN IP.

You are correct in assuming, i think, that in your case client will not be able to receive the UDP stream in information. In your case your client will have to send its WAN IP to your server to initiate the UDP connection. Finding your clients WAN IP can be tricky but there are websites that will aid your determing your WAN IP by returning it in a text page.

如果 UDP 连接是在 TCP 连接之后由服务器向客户端打开一个已知 UDP 端口的套接字创建的,那么 UPnP 可能值得研究一下,它将允许您在 NAT 上自动设置端口转发,前提是您的 NAT 支持 UPnP,就像 DSL 路由器一样.

If the UDP connection is created after the TCP connection by the server opening a socket to the client to a known UDP port then, UPnP might be worth looking into it will allow you to automatically set up your port forwards on your NAT, that is only if your NAT supports UPnP as is the case of DSL routers.

解决方法是让客户端同时向服务器打开 TCP 和 UDP 套接字.由于 NAT 后面的客户端发起了连接,因此 TCP 和 UDP 连接的状态都将添加到 NAT 的连接表中.

A work-a-round would be to client to open both TCP and UDP sockets to the server. Since the client behind the NAT initiated the connection the states of both TCP and UDP connections will be added to the NAT's connection table.

这篇关于UDP、NAT 和建立“连接"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆