Wednesday, July 11, 2018

networking - How to make a multiplayer game work reliably behind NAT?


Even games that are 100% client/server sometimes have issues when the client is behind NAT. Peee-peer games are even a bigger issues. Some games need to use multiple transports (such as UDP and TCP) or multiple connections (such as a different UDP port for voice).


What are some ways to make sure a game works reliably when running behind a NAT router?




  • Peer-Peer: No centralized server exists. Player A starts a game and Player B wants to join

  • Client-Server: A centralized server on a well known address (hostname) accepts all incoming connections. Each client only communicates with that server.

  • Combo: Where the server is just matchmaking, but game updates are peer-peer. Different peers may see each player with a different IP/port potentially (e.g. some clients are behind the same NAT and some are on a different router)



Answer



The technique most commonly used is referred to as NAT punch-through. Here's a decent intro: http://www.mindcontrol.org/~hplus/nat-punch.html


There's an OSS project at least for UDP: http://udt.sourceforge.net/index.html


RakNet supports punch-through, too, I believe. It's commercial, but has a free "Indie" license. See here: http://www.jenkinssoftware.com/


Googling for "NAT punch" will get you plenty more reading material


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...