Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Network Address Translation

This topic is 5963 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
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]

Share this post

Link to post
Share on other sites
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 ->
27661 UDP ->
27662 UDP ->

(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.


Share this post

Link to post
Share on other sites
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.



"I code therefore I am" Anon

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!