[ENet-discuss] Enet and NAT hole punching

M. Rijks enet at forge.dds.nl
Mon Jan 5 07:24:18 PST 2009


Hi everyone,

I'm happy to have found Enet as it provides the perfect mix of  
advantages between UDP and
TCP. I'm currently in planning stages of developing a client-server  
multiplayer library
on top of it. Now, in most smaller-scale multiplayer games one of the  
clients is usually
also the server. The problem with hosting the game these days however  
are firewall/NAT
routers - you need to fiddle with port forwarding to host a game.  
Connecting usually
isn't a problem as outgoing connections usually get a port forwarded  
automatically.

A popular technique to circumvent these is NAT hole punching. The  
server first connects
to a publically available session server. This outgoing message makes  
a firewall/NAT
router open up an external port for the game server. Other clients  
connect to the session
server, which then passes the external IP and port of the game server,  
so that the
clients can then connect directly to the game server. It is a nice  
technique that usually
solves much of the hosting issues for people behind a NAT router, as  
they don't even need
to know their public IP and port. There is little stress on the  
session server as it only
acts as a helper.

Let's assume that I will create my own public session server,  
preferably using Enet as
well (I'd like to keep track of a number of session statistics that  
might be of interest
to clients before joining). How would I go about setting this up?  
Naturally, it's no
problem for a client to have two outgoing connections (one to the  
session server and one
to the game server) but for the game server it's different - as far as  
I can see you're
either connecting as a client or waiting for connections as a server,  
but I need to do
both - if I set up two hosts it's going to use more than one port,  
making the connection
fail.


Any suggestions welcome, thanks in advance,

- Martin



More information about the ENet-discuss mailing list