UDP, NAT and setting up quot;connectionsquot;(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 和建立“连接"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UDP、NAT 和建立“连接"
基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01