如何通知java桌面客户端有关服务器的更改?
我想用 Java 开发一个桌面应用程序(我有非常基本的 Java 知识)。它将在客户端的计算机上运行,并从互联网上托管的服务器中提取信息。我可以设置一个计划任务,每 2 分钟连接一次服务器并检查是否有任何更新/更改,但我认为这不是一个好主意。有什么办法可以让客户知道这些变化吗?例如,当每次发生更改时,服务器都会向客户端发送更新通知?服务器可能采用不同的技术,例如Java,
我们将不胜感激任何帮助,再次感谢!
I would like to develop a desktop application with Java (I've got very basic knowledge of Java). It'll run on the client's computer and will pull information from the server hosted in the internet. I can set a schedule task to connect to the server every 2minutes and check for any update/changes but I don't think it's a very good idea. Is there any way to let the clients know about the changes? For example, when every there would a change server will send a notification to the clients to update? The server might a different technology e.g. Java
any help would be greatly appreciated, thanks again!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
向客户端推送总是很困难 - 主要是因为防火墙。在大多数情况下,使客户端从服务器(使用 HTTP)拉取更有可能起作用。
现在,您每两分钟进行一次轮询。这可能是合适的 - 或者最好少做一次(例如每天一次),具体取决于您要更新的内容。如果是客户端软件的更新,很少更新就可以了。如果是聊天对话的更新,即使两分钟也太长了 - 在这种情况下,您应该查看 彗星/长轮询作为一种技术。 (有多种技术可以实现长轮询;您不必使用任何特定的技术 - 这就是为什么我将其描述为一种技术而不是其他技术。)
Pushing to clients is always going to be hard - largely because of firewalls. Making the client pull from the server (with HTTP) is much more likely to work in most situations.
Now, you're currently polling every two minutes. That may be appropriate - or it may be better to do it much more rarely (once a day, say) depending on what you're updating. If it's updates to the client software, rare updates are fine. If it's updates to a chat conversation, even two minutes is far too long - in which case you should look into comet / long polling as a technique. (There are various technologies for implementing long polling; you don't have to use anything specific - that's why I described it as a technique rather than anything else.)
如果您使用 Java 服务器,则可以使用 JMS 将消息从服务器发送到应用程序。
或者您可以使用 Comet 应用程序通过 HTTP 将消息推送到客户端。
第三种方法是创建您自己的推送系统,您的客户端连接到服务器以提供有关如何联系的一些信息,并且使用观察者/可观察模式,您可以在每次修改时通知每个客户端。
资源:
You can use JMS to send messages from your server to your applications if you use a Java Server.
Or you could use a Comet application to push messages to the clients via HTTP.
A third way would be to create your own push system where your clients connect to the server to give some informations on how to be contacted, and with the Observer/Observable pattern you notify every client at each modification.
Resources :