UDP Hole Punching (Java)

I have been trying to create a chat / file transfer application for several weeks. I spent several hours searching the Internet for a piece of code in punching UDP holes for work, but I did not find anything that works or is simple enough for me.

I am trying to connect two clients behind routers (NAT). I was able to configure a server that shares the IP addresses and ports of the two clients, but I was unable to initiate the connection. Is there any source code somewhere that I can use?

I found several STUN / ICE / TURN libraries, such as JStun, but there is no documentation on how to use them. Do I need a STUN server to start a connection? Can I use a public one, for example numb.viagenie.ca or http://www.stunserver.org/ ?

Any answers would be greatly appreciated. Thanks!

EDITOR: I had a bit more noise, and I found that STUN is pretty easy to do even through PHP. I created my own stunning PHP that simply shares the data of two clients. The hard part is connecting two clients, but it uses something called ICE. Thanks to selbie who posted this one in the comments. This led me to the right path with ICE. I will leave this question open longer if anyone comes up with anything else. Will I start coding my own ICE code or try to find something on the Internet. Thanks!

+5
source share
1 answer

An example of UDP Hole Punching in pure Java can be found here: https://github.com/lklacar/java-hole-punching

Not supported anymore, but here is the basis for the STUN process, etc .: https://github.com/htwg/UCE

I tried to get UDP Hole Punching while working with Java clients and a PHP server, but so far I have not been able to get it working. If you have one, you can share it with us and answer the following question: Java client PHP server UDP Hole Punching sample code

+1
source

Source: https://habr.com/ru/post/1200984/


All Articles