We use the connection between the client and the RMI server on the same computer (so all ip must be localhost).
We run the registry (using port 1099 by default)
registry = LocateRegistry.createRegistry(port);
and export some objects to the RMI registry
Naming.rebind("//" + "localhost" + ":" + port + "/" + name, object);
We extract some objects from another process (remember that everything runs on the local host)
MyRemoteObject ro = (MyRemoteObject) Naming.lookup("//" + "localhost" + ":" + port + "/" + name);
The problem occurs when you start an application running on the local network, and in the middle of the process you disconnect the network connection. If you run the application and an error pop-up does not work on the local network, and if you run the application, the error pop-up does not work on the local network. This only happens when the local network changes during application startup.
The exception that occurred while executing the Naming.lookup () method is the following:
java.lang.RuntimeException: java.rmi.ConnectIOException: Exception creating connection to: 192.168.xx; nested exception is: java.net.NoRouteToHostException: No route to host: connect
Debugging a little bit i learned that
RemoteObject ($ Proxy0) โ RemoteObjectInvocationHandler โ UnicastRef2 โ LiveRef โ TCPEndpoint
had a host ip (ex: 192.168.xx) instead of "localhost" or 127.0.0.1 (what I would like). And the isLocal boolean of the liveRef object is always false.
I do not know if this is enough. Sorry!!!
Do you have any suggestions?
My attempts:
I tried these solutions
- Run jvm with the argument -Djava.rmi.server.hostname = localhost
- Redefine RMIServerSocketFactory returns 127.0.0.1 each time. (TCPEndpoint has 192.168.xx ip and isLocal is always false)
- Call the hostless retraining and search function in the URI. This is supposed to mean localhost.
but none of them worked.
Any suggestion would be welcome.
java connection localhost rmi
Rmi-thinker
source share