I am currently developing an android application which requires two devices to communicate over TCP (I can't silently loose packets so UDP is out). I need the communication to be as fast as possible (i.e. I have a low acceptable latency threshold) but the connections will be short lived (likely less than 2min). The phones will connect, do their thing, then close the connection.
I have done quite a bit of research regarding NAT hole punching, but there does not seem to be a reliable tcp hole punching method implemented for java and android. Thus, it seems my only option is to develop a server application which will "proxy" the tcp communications between the two devices.
I have two questions:
1) I don't want to re-invent the wheel: is there a simple tcp proxy already written I can use? (note: not an http proxy of any sort - because I need low latency I am simply looking to pass a very small payload between the two tcp socket connections on the devices). The sole purpose of the server is to avoid NAT issues.
2) If not, does anyone have experience with this sort of thing and what would they recommend? I have played around with the idea of Java NIO or perhaps a server that creates a new thread for each connection (the problem being how to link the appropriate "client" threads to pass the information back and forth). Or is Java even the best language to use for the server end?
I have read some recommendations of using XMPP via google's chat services (see here) but I don't want the overhead of XMPP.
Any direction or suggestions would be greatly appreciated.
As for the direct answers to your questions:
1) Not a good one I have found, it really depends on what's available on your server. I did write one some time ago in PHP and was VERY quick and simple and will work with most servers. I used this as a guide http://devzone.zend.com/209/writing-socket-servers-in-php/
If you can run a compiled C++ binary you could look here, it was an alternative we considered: http://tcpproxy.codeplex.com/
2) see answer to 1 for PHP option, I don't have experience in writing from scratch in Java.
As an aside on NAT traversal... I have been investigating the same NAT issue for project I am working on and I found 2 options that would require the NDK but could work well for NAT traversal on Android. pjnath (GPL):
www.pjsip.org/pjnath/docs/html
code.google.com/p/csipsimple/source/browse/trunk/pjsip_android/?r=201
libnice(LGPL):
nice.freedesktop.org/wiki/