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.

