Skip to main content
gamedev.net
🔒 Locked

Implementing NAT traversal

Started by Toolmaker Mar 20, 2009 at 3:35 PM 2 replies 3.7k views
Original Post
Toolmaker
Toolmaker
I'm currently experimenting a bit with the Lidgren network library. I'm planning on redoing my network code for my game and I was thinking about implementing it through NAT traversal, so don't the clients don't need to open any ports. For instance, Age of Empires does it this way, and only the host needs to open a series of ports and the rest of the clients can than perfectly fine connect to the other hosts. However, how do I implement this over UDP? Connect to the host, and then determine what the locally used port is and then start listening on that port? Or is there a way where I can punch a NAT hole on the port I intend to use as the server port(4444 in this case)? I tried to google on some articles, but can't really find information on it. Toolmaker
 
oliii
oliii
there is a very good, practical article on NAT punchthrough. I'll see if I can dig it out.

EDIT : here it is....

http://www.brynosaurus.com/pub/net/p2pnat/

hplus also has an article about NAT as well.
Everything is better with Metal.
aissp
aissp
(0) acquire udp port on client which will be using for incoming traffic
(1) Send udp packet to intermediate server
(2) The server resend your udp connection parameters to peer which want to communicate you
(3) server will notify you about peer which want to communicate with you and provide you connection parameters of this peer
(4) You and your peer start to send packets to each other using connection parameters provided by intermediate server
(5) If you cannot setup communication during some period of time, you will switch connection to intermediate server, in this case it will resend each udp packet to your communication partner.

On the step 4 you can try some sophisticated algorithm (like sending packet to set of different ports) to try make hole in symmetrical nat devices, hence, from my experience you can expect more than 90% probability that as minimum one of the pair net devices is a con nat device, so you can make hole using described straight forward algorithm. Moreover, significant amount of home routers today have got inside so-called game port option (switched on by def) this option moves router in con nat mode.


good luck
Toolmaker
Toolmaker
Quote:
Original post by oliii
there is a very good, practical article on NAT punchthrough. I'll see if I can dig it out.

EDIT : here it is....

http://www.brynosaurus.com/pub/net/p2pnat/

hplus also has an article about NAT as well.


Sweet mate, that link really helped a lot. I got it all working now, so it's a piece of cake. Now I need to proper handling of data and lost connections and I can actually start being productive with my new found knowledge.

Toolmaker
 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.