Search code examples
javarmi

How to decide which physical interface RMI Transport Layer should use?


When I use a remote reference from the client everything is OK. If I try to use this remote reference from the simu, the communication failed because the server try to use the IP from eth0. What bothers me is that the exception gets reported on the simulator. I think I missed something?

[EDIT] The simu provides this exception:

java.rmi.ConnectIOException: Exception creating connection to eth0_IP;

nested exception is: java.net.SocketException: network is unreachable

Network Configuration


Solution

  • You need to set the java.rmi.server.hostname property to tell the RMI Registry which hostname or IP Adress to return in its RMI URLs.

    This defaults to the IP address of the first interface on the system which explains why it's only working through eth0.

    So you'll need something like:

    String ipAddress = "10.1.2.3"; //IP address of eth1
    System.setProperty("java.rmi.server.hostname",ipAddress);
    

    or

    String hostname = "myserver"; //hostname that resolves for client and simu
    System.setProperty("java.rmi.server.hostname",hostname);