RMI Server behind Router: How to set the right IP?

Hi, I am having trouble with the Server of an RMI application, the set up is this:

1. The server is not always running on the same host: it may be a computer with a publicly visible and unique IP, or it may be under a computer behind a router.

2 . The user that runs the server may not know how to get his IP in the router environment.

3. The user that runs the server knows sh*t about rmiregistry or how to set a Property to the java interpreter (for example: -Djava.rmi.server.hostname=<host>).

4. The Server code is this:

/**

* Represents the Server to the Domination app (including the chat plugin).

*/

publicclass Server{

privatestaticfinalint PORT_NUM = 1099;

privatestaticfinal String CHAT ="chat";

privatestaticfinal String DOMINATION_FACTORY ="Domination";

/**

* Sets the Chat and Application Servers.

*

* @param args

*Never used.

*/

publicstaticvoid main(String[] args){

try{

Registry registry = LocateRegistry.createRegistry(PORT_NUM);

Chat chatObject =new ChatImpl();

UnicastRemoteObject.unexportObject(chatObject,true);

UnicastRemoteObject.exportObject(chatObject, PORT_NUM);

registry.rebind(CHAT, chatObject);

System.out.println("Chat ready...");

Fabrica fabricaObject =new FabricaImpl();

UnicastRemoteObject.unexportObject(fabricaObject,true);

UnicastRemoteObject.exportObject(fabricaObject, PORT_NUM);

registry.rebind(DOMINATION_FACTORY, fabricaObject);

System.out.println("Domination Factory ready...");

System.out.println("All systems up and running");

}catch (Exception e){

e.printStackTrace();

System.exit(1);

}

}

}

I wrote the code that way (and not using Naming.rebing("//" + host_name + "/Service", serviceObject)) so the server user won't need to run the rmiregistry (In fact, the Server is deployed via a jar file, so just a happy double-click to the jar will do the work)...

OK, then the problem is this: The client is always having "connection refused" Exceptions while the server is behind a router and not in the same network of the client.

The IP that is shown in the exception is always the inner IP of the host (or 10.x.x.x or 192.168.x.x or whatever it may be). So it seems that the registry is always choosing that IP and not the router's.

I need to know if there is a way to rewrite the Server code so the user just should do the same 'double-click' to run the server and not mess around "investigating" the outer IP. I read some of the RMI specs and it suggest to do IP Tunneling and some other techniques that I don't think may be appropiate to the nature of this "roaming server" application.

[3912 byte] By [Ivan_vxa] at [2007-11-26 13:24:17]
# 1

Try this out ....may help you...M not sure...

try

{

ChatImpl chatObject = new chatImpl();

(your Chat Server Interface) stub = (your Chat Server Interface)UnicastRemoteObject.exportObject( chatObject , PORT_NUM); //Type cast

Registry registry = LocateRegistry.createRegistry(PORT_NUM);

registry.bind(path, stub); //e.gpath= "com.chat.soucecode"

}

catch (Exception e)

{

System.out.println("Exception: " + e);

}

The_java_guya at 2007-7-7 17:57:52 > top of Java-index,Core,Core APIs...
# 2
Try java.rmi.server.hostname
ejpa at 2007-7-7 17:57:52 > top of Java-index,Core,Core APIs...
# 3

Thanks, but that still doesn't do the work. As I stated in the post, not every user will know how to set java.rmi.server.hostname or even look for an outer IP... I was asking for an "automagical" way to code my server class so it could do some job to do the guessing.

Even though... I tried both ways at home with the help of a friend as the client, and it seemed to work. The client connected to the server but it was kicked out in less than 30 seconds. Being specific, every client, the ones inside and the ones outside my network. As if the *only* right way was to let the JVM set the IP (but again, in that way the server is invisible to the clients outside the network).

Ivan_vxa at 2007-7-7 17:57:52 > top of Java-index,Core,Core APIs...