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 ca开发者_Python百科n 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)
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.
精彩评论