UDP Hole Punching (Java)
Asked Answered
B

1

6

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.

I'm trying to get two clients behind routers (NATs) to connect to each other. 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. 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. Do I need a STUN server to start the connection? Can I use a public one like numb.viagenie.ca or 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. I've set up my own PHP stun that just shares the two clients data. The hard part is connecting the two clients, but that uses something called ICE. Thanks to selbie who posted this in the comments. That got me on the right track with 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. Thanks!

Blastoderm answered 23/8, 2014 at 18:53 Comment(1)
Everything you need to know is here: https://mcmap.net/q/362979/-automatic-way-of-enabling-the-access-to-port-4900-from-the-internetLiberality
P
2

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

Not longer maintained but here is a framework for STUN process etc.: 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. If you have, u might share it with us and answer the following question: Java-Client PHP-Server UDP Hole Punching example code

Precedency answered 29/8, 2017 at 15:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.