0

i have a RMI server and RMI client. If the client is running its version of RMI that i made and is ready to receive connections, how can i on the Server side get the IP/Hostname of the client even if the client is not connected to me?

I was thinking of creating a remote method that will call the client to send their IP/Hostname to my server side, but that would require me to know the Client IP/Hostname to be connected to inorder to invoke the method.

The purpose of this program is to create a monitoring program to monitor what are students doing on their labs, as a teacher.

4

1 回答 1

1

即使客户端未连接到我,我如何在服务器端获取客户端的 IP/主机名?

这在术语上是矛盾的。如果没有连接,则没有当前客户端。如果您在远程方法调用期间需要当前客户端,请参阅RemoteServer.getClientHost()。如果您想要在远程方法调用期间以外的数据,您可以在远程方法调用期间收集它,但是您将很难决定何时删除客户端,除非客户端有义务调用logout()方法或类似的方法。您可以在Unreferenced.unreferenced()方法如果有帮助。但是您需要完全摆脱 RMI 中的“连接”概念。基本上没有这样的事情。连接在调用期间存在,并且在实现所需的任何额外范围内都存在,但是无法在服务器或客户端中获取它们,因此您最好设计为好像它们不存在一样,并且尽管客户端不存在,除非在远程调用期间。

或者使用我的远程会话模式,试试谷歌。

于 2012-07-13T10:15:34.333 回答