views:

59

answers:

3

Hi. I am making an IM application for Android. The application consists of a server and client, both residing on the android. At startup, the applications register with a webserver. If a client wants to send an IM to a server behind a NAT router, how this be done? I heard of stun4j and jstun but found nowhere an example of their usage in android. Thanks!

A: 

stun4j is not a universal solution which will work for all NATs.

Simplest & most reliable solution is to send messaged via your external webserver with known address.

BarsMonster
You mean to say that if A wants to send to B (both behindNAT), then :A sends to webserver and webserver sends to B.How does the webserver send to B?
B polls messages from webserver via persistent connection.Comet-like.
BarsMonster
+1  A: 

Why does the server have to be on the device?

This seems ineffective, android functions best as a typical client device.

Making an instant message app is quite simple.

Simply have the client send messages to the webserver, store them.
Have the other client(s) either wait or poll for messages from the webserver.

This will work regardless of the internet connection type.

If you're insisting on having the server on the device, I think the closest solution you'll get is to use some sort of upnp library.

With upnp you can just tell the router to automatically setup a NAT to your server's port.

This won't work for users who have disabled upnp in their routers though.

Miguel Morales
A: 

I had a similar problem in developing a soft client with IM. We licensed some software from a company called Eyeball Networks (www.eyeball.com) to solve the problem. They have a product called AnyFirewall that ensures that NAT traversal works properly through any NAT device. You can also look at their Messenger SDK which may streamline the development of your IM application, or you can use it to add VoIP and video.

Matt