简体   繁体   English

如何实现Java RMI以获取未连接的客户端ip /主机名

[英]How to implement Java RMI to get non-connected client ip/hostnames

i have a RMI server and RMI client. 我有一个RMI服务器和RMI客户端。 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? 如果客户端正在运行我制作的RMI版本并准备好接收连接,那么即使客户端未与我连接,服务器端我也如何获得客户端的IP /主机名?

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. 我正在考虑创建一个远程方法,该方法将调用客户端将其IP /主机名发送到我的服务器端,但这将要求我知道要连接的客户端IP /主机名才能调用该方法。

The purpose of this program is to create a monitoring program to monitor what are students doing on their labs, as a teacher. 该程序的目的是创建一个监视程序,以监视学生作为老师在实验室中所做的事情。

how can i on the Server side get the IP/Hostname of the client even if the client is not connected to me? 即使客户端未连接到我,我如何在服务器端获取客户端的IP /主机名?

That's a contradiction in terms. 就术语而言,这是一个矛盾。 If there is no connection there is no current client. 如果没有连接,则没有当前客户端。 If you want a current client during a remote method invocation, see RemoteServer.getClientHost() . 如果要在远程方法调用期间使用当前客户端,请参见RemoteServer.getClientHost() If you want that data other than during a remote method invocation, you can collect it during the remote method invocations, but you will have a hard time deciding when to remove a client, unless the client is obliged to call a logout() method or some such. 如果您想要的不是远程方法调用期间的数据,则可以在远程方法调用期间收集数据,但是您将很难决定何时删除客户端,除非客户端必须调用logout()方法或一些这样的。 You can clear the collection completely in an Unreferenced.unreferenced() method if that helps. 如果有帮助,您可以使用Unreferenced.unreferenced()方法完全清除集合。 But you need to get rid of the notion of 'connection' in RMI completely. 但是您需要完全摆脱RMI中的“连接”概念。 There is basically no such thing. 基本上没有这样的东西。 Connections exist for the duration of the call, and for whatever extra extent the implementation requires, but there is no way to get hold of them in either server or client, so you may as well design as though they don't exist, and as though the client doesn't exist except during a remote call. 连接在调用过程中存在,并且在实现所需的任何额外范围内都存在,但是在服务器或客户端中都无法保持它们的连接,因此,您最好设计它们好像不存在一样,并且尽管该客户端不存在,除非在远程呼叫期间。

Or use my Remote Session pattern, try Google. 使用我的远程会话模式,尝试使用Google。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM