Jump to content
  • Advertisement
Sign in to follow this  

UDP Hole Punch?

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

Game Server is UPnP enabled. works perfectly.
Client has no UPnP protocols on their router so it requires manual port settings.
But these days most games find a way around that problem and i'm guessing they are using Hole Punching.

I've researched it a bit but it's all fuzzy to me. So maybe someone can clarify the steps needed to do a HolePunch on most networks.

currently i have: (all UDP except for the HTTP ofcourse)

[color=DarkOliveGreen]Server starts, contacts master server via HTTP request and informs it "This is my port/ip/name/etc..."

[color=Navy]Client loads and makes an HTTP request to the master server and gets the serverlist, including our target [color=DarkOliveGreen]server.

[color=DarkOliveGreen]Server Listens on: <Server Customized>
[color=DarkOliveGreen]Server Sends To: 45,000

[color=DarkSlateBlue]Client Listens On: 45,000
[color=DarkSlateBlue]Client Sends To: <Server customized>

[color=DarkSlateBlue]Client does HTTP request to a master server to get the target server's IP and <ServerCustomized>port (working)

The [color=DarkSlateBlue]client sends UDP request to the [color=DarkOliveGreen]server join the [color=DarkOliveGreen]server targeting <ServerCustomized> port. (working)

[color=DarkOliveGreen]Server hears the [color=DarkSlateBlue]client request (working)
and replies to [color=DarkSlateBlue]client listening port 45000 "yes you may join" (NOT working)

as far as i can tell, the[color=DarkOliveGreen] server is sending it, but the[color=DarkSlateBlue] client doesn't hear it. I say this because it works on LAN and i haven't found a UPnP enabled tester to try it with over the internet.

to hole punch, do i just need to have the [color=DarkSlateBlue]client send the initial join request on both
<ServerCustomized> port and the 45000 port to punch a hole?

[size=1]Q: OMG! Why are you doing hole punching?
A:Because i've already found 2/3 testers that DONT have upnp routers (eg: WANPPPConnection:1 and WANIPConnection:1).

Share this post

Link to post
Share on other sites
I read something about that stuff a long time ago...

Cant you just use <ServerCustomized> for both sending and listening?

I think hole punching works like:

You have clients A and B. Both of them have a fancy NAT so they cannot connect to each other.

So, Both connect to a server C, which doesnt have a fancy NAT like that. Now C has the ports and IPs from which A and B connected to it.

Next, C tells A (or B? idk) the port of B, so that A can connect to B, because that port is already open to incoming stuff from C and thus allows connecting to it.

Something like that. I think its only needed when you want to connect 2 computers together, with both of them behind a NAT.

Go and google how it works :P

Share this post

Link to post
Share on other sites
If you have a server outside of NAT (in this case, that means with working uPnP), then you don't need NAT punch through at all.

> Client makes HTTP request to discover server IP/port
> Client make sUDP connection to server IP/port
> Server replies over the same UDP connect (i.e. the one established by the client)

UDP connections are intrinsically bi-directional, and when the client has connects to the server, you can determine the reply address from the socket.

Share this post

Link to post
Share on other sites
Hole punching (and uPNP) is only needed when both ends of a communication are behind NATs. If one is a public server, no hole punching is needed.
When you do hole punching, you have a spearate "introducer" server that is outside a NAT, and introduces the two endpoints to each other. This is also useful for matchmaking.
The FAQ talks about UDP NAT punching, and has some links to explanations and libraries you can check out.

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!