在Java RMI中,客户端如何知道其服务器已经死机? [英] In Java RMI, how can a client know that its server is dead?

查看:95
本文介绍了在Java RMI中,客户端如何知道其服务器已经死机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在开发一个基于Java RMI构建的聊天服务器 - 客户端程序。为了让客户端检测到其连接的服务器已经死亡,我只能想到两种可能的解决方案,但在我的情况下它们都不能正常工作。

1。等到客户端需要调用服务器的某些方法,这种方式不能很好地工作,因为如果聊天客户端没有调用任何服务器的方法,它就不会知道服务器已经死了,因此聊天客户端无法接收任何新的那段时间的聊天消息了。

2。每隔几秒钟调用服务器的方法进行例行检查。但这会带来大量的开销。

这种情况有更好的方法吗?

非常感谢。

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.

推荐答案

所以似乎没有人回答这个......你怎么样?知道某件事是否已经死了而没有与之交互?

So nobody seems to be answering this ... How would you know if something is dead without interacting with it?

在IRC中,服务器会定期ping客户端以检查它们是否仍然连接......你会看到平安! Pong!在客户端窗口中,有时客户端会尝试发送消息,发现它没有连接。

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

这篇关于在Java RMI中,客户端如何知道其服务器已经死机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆