configuring RMI host so that it should know which client port is accessing it

前端 未结 2 1024
悲&欢浪女
悲&欢浪女 2020-12-12 04:37

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

相关标签:
2条回答
  • 2020-12-12 04:59

    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.

    0 讨论(0)
  • 2020-12-12 05:16

    configuring RMI host so that it should know which client port is accessing it

    1. There is no 'configuration' of the RMI host that will deliver that information.

    2. The client port information is completely and utterly useless.

      • It isn't unique per client.
      • It isn't fixed per client.
      • It can and will change over the life of the client.

    It sounds like a case for the Remote Session Pattern to me.

    0 讨论(0)
提交回复
热议问题