views:

828

answers:

2

I'm trying to find a way to communicate between two NAT-ed nodes using Java. My requirements pretty much align with the ICE-specification; i.e. I want to try STUN first and then fall back to relaying the data when nothing else works. I need some kind of streaming protocol, so either TCP must be supported or the library should provide some kind of streaming and error correction-abstraction on top of UDP (like libjingle does).The relaying must be decentralized, i.e. go through other nodes in the network and not through a central server.

Does anyone know any good implementations of this in Java?

Google's libjingle (http://code.google.com/apis/talk/libjingle/index.html) seem to provide pretty much what I'm looking for. Unfortunately it's written in C++. Do you think I should try that using JNI or are there any Java-clones of libjingle? I've briefly looked at Smack (http://www.igniterealtime.org/projects/smack/index.jsp) but I can't really find if it provides the features I'm looking for.

+2  A: 

You might look at UPNPlib which would allow you to programatically open ports in the router.

Jherico
Thanks but unfortunately UPNP does not work 100% of the time so I still need to handle the cases where the router doesn't support UPNP (or has it disabled). It would be a good complement to an ICE-based solution though, since it would reduce the risk of having to relay the data.
Yrlec
+1  A: 

Here are some Java libraries implementing NAT traversal:

  • PJNATH - PJNATH (PJSIP NAT Helper) is an open source library providing NAT traversal functionalities by using standard based protocols such as STUN, TURN, and ICE.
  • JStun - a Java-based STUN (Simple Traversal of User Datagram Protocol (UDP) Through Network Address Translation (NAT)) implementation
    • Freecast - Node can perform STUN requests to determinate its public address. Required for NAT traversal. Use Jstun API (http://jstun.javawi.de/).
Dougnukem