1

How do online multiplayer games which use UDP get the packets delivered between networks over the internet? From what I understand, clients would have to enable port forwarding on their routers in order for the packets to arrive at their computer. Is this what big online games (WoW, Diablo, etc) require players to do?

For example, I recently created a server that handles udp traffic. It just echos back whatever a sender has sent. I deployed this to a server on the internet. I can only get the echos back to the sender after enabling port forwarding, but this will not work if there are two senders on the same local network.

diaper
  • 13
  • 3

1 Answers1

3

Short answer: NAT Connection tracking

One thing to remember is that the vast majority of Routers on the IPv4 internet is NAT Routers.

Most NAT implementations does smart tracking, When you send UDP from a internal client to somewhere you will have a Destination Port and a Source Port. If traffic comes in with the ports reversed, then that traffic will be routed back to your client, and allowed in most firewalls.

NAT/Firewalls with tracking detects these packets as related and forwards them back.

Example based on comments with server on port 5000 UDP

  • Client sends a packet for server:5000, source client:5001
  • First NAT router will see a packet with source ip and port of client:5001, and destination server:5000.
  • Router sends this on it's way, and will have NATip:NATport
  • Server receives this and creates a response to NATip:NATport that has the source of server:5000
  • NAT receives this and has source server:5000 destination NATip:NATport, which matches the packet that was sent out (but has source and destination reversed)
  • NAT sends this to client:5001 still with source server:5000

The source ip+port and destination ip+port creates a combination that can be tracked. (there is more details, but this is the basics)

Some more reading But I should dig up better documentation on this and not just refer to anecdotal evidence from what I have seen experienced.

NiKiZe
  • 1,246
  • 8
  • 20
  • can you explain what you mean by "if traffic comes in with the ports reversed"? Does that mean if my server outside the NAT received a packet on port 5000 from :5001, then it should send back a reply to :5000? – diaper Aug 08 '21 at 07:02
  • @diaper example added – NiKiZe Aug 08 '21 at 09:44
  • See also https://en.wikipedia.org/wiki/Hole_punching_(networking) – user10489 Aug 08 '21 at 12:10
  • @NiKiZe thanks, that makes sense. Sounds like hole punching is basically "send packet more than once because the first might be dropped" I wish I could figure out why my example app still does not work, while other things on my network work without port forwarding (xbox, zoom calls, etc) but that's a whole other question – diaper Aug 08 '21 at 15:11
  • Most NAT routers allows the traffic, make sure that you are returning data to the same port that the traffic came from. Server has static port number, client has a random port number as source. – NiKiZe Aug 08 '21 at 17:02