2

I want to use NAT hole-punching in one of my java applications, but I don't know where to start. I'd like some sample code to start off with.... (I have access to a PHP server with sockets, cURL, and server sockets, so some PHP server code would be appreciated too...)

Thanks in advance.

EDIT: I am sorry, I was not clear enough. I want to know how to create a PHP server that can be "the middleman" for hole punching. I also want to know how to make a java application that can connect to the PHP server, and maintain that connection while another java application connects to the first one on the same port. (Which is my impression of how NAT hole punching works)

user969931
  • 96
  • 5
  • 1
    Have you done any research? Did you at least google for "UDP NAT Hole Punching"? Do you understand what is needed? – Jim Garrison Sep 28 '11 at 21:22
  • Yes I do. I understand how it works, but not how to actually do it... (Googled everything to do with it but I still couldn't find any sample code to start off with...) – user969931 Oct 05 '11 at 18:21
  • If you explained what concepts you are having trouble with you might get more help. Are you trying to implement a hole-punch mediating server? Do you already have such a server and want to know how to configure it? Your question as it currently stands is not answerable. – Jim Garrison Oct 05 '11 at 20:05

1 Answers1

0

You need to learn about STUN. You also need to learn about conditions under which nat traversal is possible (and when it is not). You can read chapter 4 of the Practical JXTA II book available online at scribd. If STUN is not possible, then you need to rely on TURN.

I don't have PHP code examples to provide, but when you will understand how it works, you'll see it is not that complicated to implement. You only need to retrieve translated IP addresses and ports from the middleman, and that's basically it.

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
  • Also for reference [here](http://tools.ietf.org/html/rfc5389) is the STUN RFC - always a good idea to learn how to read those. Most are really well written and often have a good introduction to the topic or at least link to the RFC that includes it. – Voo Nov 04 '11 at 04:28
  • @Voo, I have a similar question. Problem is it is not that simple, just like we don't have to implement TCP ourself, i am wondering are there any open source libraries available that implement this functionality, as i have gone through the concepts but implementing the whole protocol is too much work. I would appreciate if you know of any free libraries that provide similar functionality – Johnydep Jan 30 '12 at 12:59