Advertisement

Network Address Translation

Started by March 21, 2002 11:12 AM
2 comments, last by Convict@Large 22 years, 10 months ago
Is it actually possible to communicate with a client/server behind a NAT enabled router? If so how is it done? Cheers, Convict@Large "I code therefore I am" Anon
DanielB - Slayer of Bugs
As long as the computer behind the NAT router initiates all communication, it should 'just work.'

If you want a client outside to initiate a connection to a server inside, the person running the router will have to set up some port forwarding rules, but you don't have to program your app any differently.

[edited by - cheesegrater on March 21, 2002 12:23:52 PM]
Advertisement
I''m assuming you are talking about playing games through a NAT.

Are you talking about with existing games or are you planning on coding a game?

Half-life does an excellent job at doing this (in most NAT configurations). Unreal Tournament does too (but seems to lag a bit more when using NAT).

Even Quake III can be configured to work through a NAT with multiple clients inside the firewall and the server outside.

In almost all games, the server must NOT be behind a NAT, or the port to the server must be properly forwarded. Sometimes, you have to DMZ the server.

Usually, in client-server, the server listens on a known port. The clients connect to the known port on the server (just like a browser connects to the known port 80 for the web).

For the clients, you should allow each client to either
1) automatically pick a dynamic port to use for the connection,
2) change the client port.

Half-life seems to do a good job picking the client port (although it seems to restrict it to the 27xxx range). I have found certain firewalls that half-life won''t work with (like at school, but they use a firewall WITHOUT a NAT).

Quake 3 uses a static client port, but you can run it with a command line parameter to change the port of each client, and forward that port to each computer.

For example, you could set up 3 clients inside the NAT to run Quake like this

quake3.exe +set net_port 27660
quake3.exe +set net_port 27661
quake3.exe +set net_port 27662

And then forward each port to the IP of each computer:
27660 UDP -> 192.168.1.10
27661 UDP -> 192.168.1.11
27662 UDP -> 192.168.1.12

(Or whatever your IP addresses are.)

I use this method to play games like Q3 and RtCW through my router. Like I said, Half-life seems to be easier to set up. Unreal Tournament actually shares the IP, although I''m not sure how it works.

You can also put your client in the DMZ (this works for servers too), but this will only let you use one computer behind the NAT.

Other applications can be tricked to bypassing firewalls by using an external proxy server and a program like SocksCap. I used to use this to connect to Ultima Online at school. I had a proxy server exposed on my computer at home, and I would set up UO to connect through my computer. However, this creates a lot of extra lag.

If you are coding a game, try to do it like Half-Life or UT. However, if you must do it like Q3, allow the user to choose which port each client uses.

--TheMuuj
--TheMuuj
Thanks for that info, I am currently coding a network lib and it just occured to me that I was not sure about how to deal with NAT. But based on what you have said my lib should work fine.

Cheers,

Convict@Large

"I code therefore I am" Anon
DanielB - Slayer of Bugs

This topic is closed to new replies.

Advertisement