Jump to content
  • Advertisement
Sign in to follow this  
Josh Klint

enet and NAT punch-through

This topic is 2782 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

A search for enet and NAT punch-through yields a lot of questions about whether this is possible and discussion of how it might be done, but I have never found an actual instance of working code, or anyone who claims to have successfully implemented NAT punch-through with enet.

I love the simplicity of enet, but without NAT punch-through support, I don't see how it is useful for networked software. If enet is a dead end I would like to abandon it now. Your thoughts?

Share this post


Link to post
Share on other sites
Advertisement

A search for enet and NAT punch-through yields a lot of questions about whether this is possible and discussion of how it might be done, but I have never found an actual instance of working code, or anyone who claims to have successfully implemented NAT punch-through with enet.

I love the simplicity of enet, but without NAT punch-through support, I don't see how it is useful for networked software. If enet is a dead end I would like to abandon it now. Your thoughts?



Punch-through requires external information in addition to just the client library.

Specifically, you need to be able to set up a server, that both clients can talk to. That server can then tell both clients to start the punch-through traversal connection attempt at the same time.

If Enet lets you specify the port to bind to for both outgoing and incoming traffic, and re-use the same port/socket for multiple outbound connections, then you can use Enet for your punch-through, as well as for the introduction server.

Share this post


Link to post
Share on other sites
So how this works is:

Client - player who wants to play game
Server - player who wants to host game
Participant #3 (for lack of a better term) - program running on a dedicated server

Client and Server both creates client hosts that connect to Participant #3, which is running at a known IP address, on a known port.

Participant #3 gets Server's IP address and port, and sends this information to Client.

Client uses this information to immediately connect to Server, using the IP address and port provided by Participant #3.

Is that correct? So really the only time you need this is when Server is behind a router. If Server was a player plugged straight into a modem, or Server was a dedicated server, this would not be necessary.

Share this post


Link to post
Share on other sites
That sounds about right. But AFAIK you also want the server to receive the external IP of the client, and have it send some (potentially bogus) messages to that endpoint. This will help some routers realize that messages FROM that external IP should be routed to that particular endpoint behind the router.

Share this post


Link to post
Share on other sites
This sounds interesting and horribly prone to error. It will be neat to see what happens in the initial tests. :lol:

Share this post


Link to post
Share on other sites

Participant #3 gets Server's IP address and port, and sends this information to Client.

Client uses this information to immediately connect to Server, using the IP address and port provided by Participant #3.

Is that correct? So really the only time you need this is when Server is behind a router. If Server was a player plugged straight into a modem, or Server was a dedicated server, this would not be necessary.


Specifically, you need NAT punch through when the server is behind a NAT. Some "modems" implement NAT. Some "routers" do not implement NAT.

However, your description is not quite correct -- the server also needs to get the information about the client, and attempt to create a connection to the client at the same time as the client attempts to create the connection to the server. This is the crucial part that lets the NAT on the server side know to "let through" incoming packets from the client (who has another external IP address than #3, the introducer).

Commercial libraries that do NAT punch-through will do some additional tricks to make it work better.
For example, some routers will put a remote IP on a blacklist if they receive an unsolicited message. Thus, the introducer will sequence each "generation" of packets, where each "generation" has a TTL one larger than the previous. This lets packets go OUT before they come IN at each side. Start with a TTL of 2.
Other routers do "symmetric" NAT (which arguably breaks the UDP specification), and allocates a new external port for each remote IP/port pair. For those routers, the other side needs to try not just the reported port, but also some other ports, typically incremented or decremented from the initially discovered port.
A good library will collaborate with the introducer to figure out the behavior of the local NAT, and store information about it locally (or on the introducer!) so that it can be re-used later for faster subsequent matches.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!