We are using a client/server RMI communication in the same computer (so all ip should be localhost).
We start the registry (using the default port 1099)
registry = LocateRegistry.createRegistry(port);
and export some objects to the RMI registry
Naming.rebind("//" + "localhost" + ":" + port + "/" + name, object);
From another process we retrieve some objects (remember everything runs in localhost)
MyRemoteObject ro = (MyRemoteObject) Naming.lookup("//" + "localhost" + ":" + port + "/" + name);
The issue happen when you run the app starting with local area network working and in the middle of the process you disable the network connection. If you run the app and the LAN is working no issue popup, and if you run the app and the LAN is not working no issue popup. It just happens when you change the LAN while you are running the app.
The exception thrown while executing Naming.lookup() method is this one:
java.lang.RuntimeException: java.rmi.ConnectIOException: Exception creating connection to: 192.168.x.x; nested exception is:
java.net.NoRouteToHostException: No route to host: connect
Debugging a little bit I found out that the
RemoteObject ($Proxy0) -> RemoteObjectInvocationHandler -> UnicastRef2 -> LiveRef -> TCPEndpoint
had the ip of the host (e.g.: 192.168.x.x) instead of "localhost" or 127.0.0.1 (what it would be what I wanted). And the isLocal boolean of liveRef object is always false.
I don't know if it is clear enough. Sorry!!!
Do you have any suggestions?
I tried this solutions
but none of these have worked.
Any suggestion will be welcome.
java.rmi.server.hostname
should do the trick. You did set it on server, right?
If java.rmi.server.hostname=localhost
does not work, how about java.rmi.server.hostname=127.0.0.1
or java.rmi.server.hostname=::1
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With