Sign in to follow this  

UDP hole punching

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

Hi, I'm new here:)
I've created a simple app using VoIP client-server.
Now i see i need to use
http://en.wikipedia.org/wiki/UDP_hole_punching , because the server can't handle many clients.
I've no idea how I am supposed to implement that in my code.Anyone could help?:P

Share this post


Link to post
Share on other sites
Yes I know how to send UDP Packet.
According to the alghoritm
[quote]
Let A and B be the two hosts, each in its own private network; N1 and N2 are the two NAT devices; S is a public server with a well-known globally reachable IP address.

[list=1][*]A and B each begin a UDP conversation with S; the NAT devices N1 and N2 create UDP translation states and assign temporary external port numbers[*]S relays these port numbers back to A and B[*]A and B contact each others' NAT devices directly on the translated ports; the NAT devices use the previously created translation states and send the packets to A and B[/list]
[/quote]
Okay let's say i have a global server S . Now i run clients on A and B who send UDP packet saying 'hello i want to connect to another pc'. Server gets the [u]IPs[/u] of A and B [u]routers.[/u]
[quote]
the NAT devices N1 and N2 create UDP translation states and assign temporary external port numbers
[/quote]
i don't understand this, how to do that.. ?

Share this post


Link to post
Share on other sites
[quote name='troopson' timestamp='1311440661' post='4839313']
[quote]
the NAT devices N1 and N2 create UDP translation states and assign temporary external port numbers
[/quote]
i don't understand this, how to do that.. ?
[/quote]

That's what your router is doing -- you don't do anything.

Btw: the forum FAQ contains several links to this topic, and I wrote an article in Game Programming Gems 5 about this that you might want to find at the library.

Share this post


Link to post
Share on other sites
Firstly I'd like to thank for the helpful responses :)
I read [url="http://www.mindcontrol.org/%7Ehplus/nat-punch.html"]http://www.mindcontr.../nat-punch.html[/url], which was very helpful. Its food for thoughts.
Is it possible to test it inside 1 network? e.g. im 192.168.2.2,second pc is 192.168.2.3 and the main server is 192.168.2.4, the nat is 192.168.2.1
Guess not?

Share this post


Link to post
Share on other sites
[quote name='troopson' timestamp='1311608232' post='4840020']
Firstly I'd like to thank for the helpful responses :)
I read [url="http://www.mindcontrol.org/%7Ehplus/nat-punch.html"]http://www.mindcontr.../nat-punch.html[/url], which was very helpful. Its food for thoughts.
Is it possible to test it inside 1 network? e.g. im 192.168.2.2,second pc is 192.168.2.3 and the main server is 192.168.2.4, the nat is 192.168.2.1
Guess not?
[/quote]

You need a network that looks something like:

[code]box 1 -> NAT ->
Network -> Introducer
box 2 -> NAT ->
[/code]

I have to admit, when I tested this, I used a server on the Internet, and my home and then-work computers as the two boxes behind NAT, so I did it "live."

However, with a proper VMWare "team" set-up, you may be able to do this with only two machines. Specifically, your host machine running the two behind-NAT virtual machines, and your regular desktop, would be the "box1," "box2" and "NAT" parts. It probably can't be the "introducer" part unless the VMWare NAT virtual network is very, very good (and my experience has been that it isn't) -- I'd plan on having another, physical, box for that.

Also, they need to be on different networks! box1 and box2 may be on 192.168.1.x nodes; the "introducer" needs to be on a different class of network -- 10.x, or 172.x, or with a proper IP address. (Theoretically, if you use net masks properly, you could also put the insides on 192.168.2.1, and put the introducer on 192.168.1.1)

Or, if you're going guerilla, you could just put up a second router -- they can be had for $40 mail order these days. You would need two network interfaces on your host computer. Hook it up something like:
[code]VM1 -> bridged interface 2 -> Router2 ->
Introducer -> bridged interface 1 -> Router1 -> Internet
VM2 -> bridged interface 2 -> Router2 ->
[/code]

"introducer" would run on the host machine, and only on interface 1, so it's logically on a different network.

Btw: if you don't have VMWare, then downloading Virtual PC is free for Windows, and Linux comes with kvm-qemu. You could also download VirtualBox for either platform. Their network configuraitons may not be quite as slick, but should be possible to bend to the functions you need, assuming you really understand how networks, interfaces, and addresses interact.

Share this post


Link to post
Share on other sites

This topic is 2338 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this