简体   繁体   English

在Java RMI中,客户端如何知道其服务器已死?

[英]In Java RMI, how can a client know that its server is dead?

Currently, I'm working on a chat server-client program which is built on Java RMI. 目前,我正在研究基于Java RMI构建的聊天服务器-客户端程序。 In order for a client to detect that its connected server has been died, I can only think of two possible solutions, but neither of them works well in my case. 为了使客户端能够检测到其连接的服务器已死,我只能想到两种可能的解决方案,但是在我的情况下,它们都不能很好地工作。
1. Wait until the client needs to invoke some methods of the server, this way does not work well because if the chat client does not invoke any method of server, it will not know that server is dead, thus the chat client can not receive any new chat message in that time anymore. 1.等到客户端需要调用服务器的某些方法后,这种方法无法正常工作,因为如果聊天客户端不调用服务器的任何方法,它将不知道服务器已死,因此聊天客户端无法接收那时再没有任何新的聊天消息。
2. Routine check by invoking a server's method every few seconds. 2.通过每隔几秒钟调用一次服务器的方法进行例行检查。 But this introduces a large amount of overhead. 但这会带来大量的开销。
Is there any better way for this case? 在这种情况下,还有什么更好的方法吗?
Thank you very much. 非常感谢你。

So nobody seems to be answering this ... How would you know if something is dead without interacting with it? 因此,似乎没有人在回答这个问题。。。如果不与之互动,您怎么知道某物是否死了?

In IRC the server will periodically ping clients to check that they're still connected ...You will see Ping! Pong! 在IRC中,服务器会定期对客户端进行ping操作,以检查它们是否仍在连接...您将看到Ping! Pong! Ping! Pong! in the client window and sometimes a client will attempt to send a message only to find that it has no connection. 在客户端窗口中,有时客户端会尝试发送一条消息,只是发现它没有连接。

If you are worried about overhead .. just don't do it so often 如果您担心开销..那就不要经常这样做

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

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