简体   繁体   English

UDP打孔(Java)

[英]UDP Hole Punching (Java)

I've been trying to create a socket chat/file transfer application for several weeks now. 我一直在尝试创建套接字聊天/文件传输应用程序几周。 I've spent hours searching on the internet for a piece of code on UDP hole punching to work with, but I haven't found anything that works or is simple enough for me to use. 我花了几个小时在互联网上搜索关于UDP打孔的代码片段,但是我没有发现任何有效或足够简单的东西供我使用。

I'm trying to get two clients behind routers (NATs) to connect to each other. 我正试图让两个客户端在路由器(NAT)之后相互连接。 I've managed to set up a server that shares the two clients IPs and ports, but I haven't managed to actually initiate a connection. 我已经设法建立一个共享两个客户端IP和端口的服务器,但我还没有设法实际启动连接。 Is there any source code anywhere that I can use? 我可以在任何地方使用任何源代码吗?

I've found several STUN/ICE/TURN libraries like JStun, but there's no documentation on how to use them. 我找到了几个像JStun一样的STUN / ICE / TURN库,但没有关于如何使用它们的文档。 Do I need a STUN server to start the connection? 我是否需要STUN服务器才能启动连接? Can I use a public one like numb.viagenie.ca or http://www.stunserver.org/ ? 我可以使用像numb.viagenie.ca或http://www.stunserver.org/这样的公共网站吗?

Any answers would be greatly appreciated. 任何答案将不胜感激。 Thanks! 谢谢!

EDIT: I've had a bit more poking around, and I've discovered that STUN is fairly easy to make even through PHP. 编辑:我有更多的讨论,我发现即使通过PHP,STUN也很容易。 I've set up my own PHP stun that just shares the two clients data. 我已经设置了自己的PHP stun,只是共享两个客户端数据。 The hard part is connecting the two clients, but that uses something called ICE. 困难的部分是连接两个客户端,但这使用了一个名为ICE的东西。 Thanks to selbie who posted this in the comments. 感谢selbie在评论中发布此内容 That got me on the right track with ICE. 这使我与ICE走在正确的轨道上。 I'll leave this question open for a bit longer in case somebody comes up with anything else. 如果有人想出其他的话,我会把这个问题保持开放一段时间。 I'll start coding my own ICE code, or try and look for something online. 我将开始编写自己的ICE代码,或尝试在线查找内容。 Thanks! 谢谢!

An example of UDP Hole Punching in pure Java can be found here: https://github.com/lklacar/java-hole-punching 可以在此处找到纯Java中UDP Hole Punching的示例: https//github.com/lklacar/java-hole-punching

Not longer maintained but here is a framework for STUN process etc.: https://github.com/htwg/UCE 不再维护,但这里是STUN流程的框架等: https//github.com/htwg/UCE

I ve tried to get UDP Hole Punching working with Java Clients and PHP Server as well but could not get it working yet. 我试图让UDP Hole Punching与Java客户端和PHP服务器一起工作但是还没有让它工作。 If you have, u might share it with us and answer the following question: Java-Client PHP-Server UDP Hole Punching example code 如果您有,您可以与我们分享并回答以下问题: Java-Client PHP-Server UDP Hole Punching示例代码

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

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