开发者

UDP Client - Open Ports?

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 reg开发者_StackOverflow中文版ular WiFi, can I send UDP to the client without having opening ports problem?

Thanks.


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:

  1. Packet originated from home computer with IP 5.5.5.5. Lets say it has source UDP port 55555, source IP address 5.5.5.5 and destination port 8888.
  2. Packet reaches home router. As it is going from inside - router allows it to pass through and creates rule say for 2 minutes to allow packets targeted to 5.5.5.5 to UDP port 55555.
  3. Packet reaches corporate router before your server. It has rule to pass packets for port 8888 so packet is allowed to go.
  4. Your server receives the packet and processes it. In response it creates packet for IP 5.5.5.5 and UDP port 55555.
  5. Corporate router allows response to go.
  6. Home router allows response to go according to temporary rule.
  7. Your computer receives the response.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜