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

耗尽温柔 提交于 2019-12-03 18:11:26

问题


Currently, I'm working on a chat server-client program which is built on 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.
2. Routine check by invoking a server's method every few seconds. But this introduces a large amount of overhead.
Is there any better way for this case?
Thank you very much.


回答1:


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! 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



来源:https://stackoverflow.com/questions/19274163/in-java-rmi-how-can-a-client-know-that-its-server-is-dead

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!