Take the 2-minute tour ×

Let's say the public IP of the router is
The local IP of the computer with the server is
The router is set to forward to

In the server I have:

System.setProperty( "java.rmi.server.hostname" , "" );
Registry registry = LocateRegistry.createRegistry( 5678 );
registry.rebind( "TheWebServer" , webServerInt );

The client has:

Registry registry = LocateRegistry.getRegistry( "" , 5678 );
server = (WebServerInterface) registry.lookup( "TheWebServer" );

When client is on the network local to the server it's ok. When the client is outside the local network it gets java.rmi.ConnectException: Connection refused to host:;

Obviously the server is giving the client the IP of as it doesn't appear in the code, which I thought System.setProperty( "java.rmi.server.hostname" , "" ); was supposed to change.

Any input would be greatly appreciated.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You need to export your remote objects on port 5678 too, and you need to set java.rmi.server.hostname before you export any remote objects.

share|improve this answer

Your Answer


