UDP 客户端 - 打开端口?
所以现在我只为我的客户端使用 TCP - 它们连接到服务器,打开套接字并自由获取数据包。 但是,如果我决定在游戏中也使用 UDP,该怎么办?他们必须开放港口吗?例如,如果他们使用常规 WiFi,我可以将 UDP 发送到客户端而不会出现打开端口问题吗?
谢谢。
So right now I'm using only TCP for my clients - they connect to the server, open socket and freely getting packets.
But what if I will decide to use also UDP in my game? Will they gonna have to open ports? For example, if they are using a regular WiFi, can I send UDP to the client without having opening ports problem?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TCP 和UDP 只是传输层实现的两个示例。它们都使用术语“端口”来确定哪个应用程序应该接收传入数据包,但它们可以通过路由器/交换机/防火墙/等进行不同的路由/过滤。
所以答案是否定的。打开端口时您也会遇到类似的问题。除了“TCP端口xxx应该打开”之外,您还必须要求“UDP端口xxx应该打开”。
在大多数家庭网络中,防火墙规则允许将传出数据包(请求)发送到任何远程端口(例如,在您的服务器上,应打开此端口)。当这样的数据包通过路由器时,它会创建临时规则以允许答案返回到请求数据包的本地端口。
因此,正常情况是这样的:
5.5.5.5
的家庭计算机。假设它有源 UDP 端口55555
、源 IP 地址5.5.5.5
和目标端口8888
。5.5.5.5
的数据包到达 UDP 端口55555
。8888
,因此数据包被允许通过。5.5.5.5
和 UDP 端口55555
创建数据包。为了确保安全,公司计算机和路由器通常会受到更多限制,因此如果您的用户(IP
5.5.5.5
)位于公司网络中,第二点可能会限制数据包。它非常简单,因为实际上几乎总是有像 NAT 这样的东西,并且规则更复杂......但总的来说,它给出了它内部如何工作的想法。
TCP and UDP are just two examples of transport layer implementations. Both of them are using term 'port' to determine which app should receive incoming packet, but they could be routed/filtered differently by routers/switches/firewalls/etc.
So the answer is no. You will have similar problems with opening ports. Just except 'TCP port xxx should be opened' you have to demand 'UDP port xxx should be opened'.
In most home networks firewall rules allow outgoing packets (requests) to any remote port (on your server for example, where this port should be opened). And when such a packet goes through a router - it creates temporary rule to allow answers come back to the local port from which request packet.
So, normal scenario is like that:
5.5.5.5
. Lets say it has source UDP port55555
, source IP address5.5.5.5
and destination port8888
.5.5.5.5
to UDP port55555
.8888
so packet is allowed to go.5.5.5.5
and UDP port55555
.Corporate computers and routers often more restrictive to ensure security, so second point could restrict packet if your user (IP
5.5.5.5
) is in corporate network.It is very simplified as in reality there's almost always things like NAT and rules are more complex... But in general it gives the idea how it works internally.