I have been working on spring RMI and I have set up a host and one client.
Below is the code of my host. I want to modify it in such a way that host should know whic
You can solve the problem in multiple ways.
1) You can add one method like registerClient(String clientId, Object clientInfo) in remote interface. You can pass other relevant information in additional parameters of this method. RMI server can simple put this info in data structure like ConcurrentHashMap.
2) After invoking registerClient, you can invoke other remote methods in RMI server by passing clientId as one of the parameters in Remote methods like cube(String clientId, int num);
3) If you just need only client IP, Java already provides getClientHost()
API in RemoteServer
which provides the information you are looking for.
configuring RMI host so that it should know which client port is accessing it
There is no 'configuration' of the RMI host that will deliver that information.
The client port information is completely and utterly useless.
It sounds like a case for the Remote Session Pattern to me.