简体   繁体   English

PHP和Java用于UDP NAT打孔...?

[英]PHP and Java for UDP NAT hole punching…?

I want to use NAT hole-punching in one of my java applications, but I don't know where to start. 我想在我的一个Java应用程序中使用NAT打孔,但是我不知道从哪里开始。 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...) 我想要一些示例代码开始于...。(我可以访问带有套接字,cURL和服务器套接字的PHP服务器,因此,一些PHP服务器代码也将受到赞赏...)

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. 我想知道如何创建一个可以成为打孔“中间人”的PHP服务器。 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. 我还想知道如何制作一个可以连接到PHP服务器的Java应用程序,并在另一个Java应用程序连接到同一端口上的第一个Java应用程序时保持该连接。 (Which is my impression of how NAT hole punching works) (这是我对NAT打孔的工作方式的印象)

You need to learn about STUN. 您需要了解STUN。 You also need to learn about conditions under which nat traversal is possible (and when it is not). 您还需要了解在哪些情况下可以进行nat遍历(以及何时不能遍历)。 You can read chapter 4 of the Practical JXTA II book available online at scribd. 您可以在scribd上在线阅读《实用JXTA II》一书的第4章。 If STUN is not possible, then you need to rely on TURN. 如果无法执行STUN,则需要依靠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. 我没有提供PHP代码示例,但是当您了解它的工作原理时,您会发现实现起来并不那么复杂。 You only need to retrieve translated IP addresses and ports from the middleman, and that's basically it. 您只需要从中间人那里获取翻译后的IP地址和端口,基本上就是这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM