问题描述
我想用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!
推荐答案
将推送到客户端总是很难 - 主要是因为防火墙。在大多数情况下,从服务器(使用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桌面客户端有关服务器的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!