Search code examples
javarmi

RMI : determine the IP address of a remote object


I have functioning RMI client-server system. The server's host information is known to the clients so they can look it up and make calls. On first call to the server, the clients pass the server a remote reference of "themselves" so that the server can make callbacks. The server maintains a list of the all connected clients (when a client shuts down it "unregisters" from the server, and there is a thread that periodically checks if the clients are reachable and evicts the ones that are not).

There is a graphical interface (part of a webapp) on the server that allows the users to visualize the clients that are connected at any time. Now I am asked to display the clients' IP address in this interface.

My question : in RMI, if you have a remote reference of a remote object (a stub), is there a simple way to determine the host (DNS name or IP address) on which this remote object actually lives ?

Note : I could use RemoteServer.getClientHost when the client first connects and store the info, or I could implement a remote method on the client that returns the host info, but I wish to know if there is a built-in RMI way of doing it with the remote reference.


Solution

  • RMISecurityManager and the UnicastRemoteObject don't say anything about that.
    You can use the RemoteServer.getClientHost when the client connects.
    I don't believe that this information can be obtained unless it is passed in the remote method call.