Score:1

How do online games send UDP packets across the internet?

ca flag

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.

Score:3
in flag

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.

diaper avatar
ca flag
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 <some ip>:5001, then it should send back a reply to <some ip>:5000?
in flag
@diaper example added
user10489 avatar
nc flag
See also https://en.wikipedia.org/wiki/Hole_punching_(networking)
diaper avatar
ca flag
@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
in flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.