Getting the IP address of RMI clients
843793Dec 6 2004 — edited Dec 7 2004I have developed an RMI server class and a RMI client class, each with its own Remote Interface.
I want both clients and server to call methods from each other to exchange data.
Here is what I have coded.
The server object starts by creating a Name registry "LocateRegistry.createRegistry(1099)"), and then binds itself to it, using name "server".
On another machine, a client is created. It creates a Name Registry too and binds itself to it (using a unique name).
Then the client asks the server's remote registry for a remote reference to the server (it knows the server's IP adress and it knows that the registry is on port 1099).
It then calls a connect(clientName, clientRegistryPort) remote procedure which provides the server with the client's name and registry port, as the arguments suggests.
The goal is to enable the server to get a remote reference to the client.
But my problem is, to do this the server needs the client's IP address. I am sorry if this looks like a dumb question, but how can the server know the client's IP address ?
Of course the client could send it, but wouldn't it be a more elegant method if the server to found it by itself (after all, a connection is already established since the client has called a method on the server) ? Does RMI provide a method for this ? Do you think that my general solution is correct ?