how to notify java desktop clients about changes from server?

旧街凉风 提交于 2019-12-07 07:54:44

问题


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!


回答1:


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.)




回答2:


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 :

  • Oracle.com - JMS
  • Wikipedia - Comet
  • Wikipedia - Publish/Suscribe


来源:https://stackoverflow.com/questions/3671998/how-to-notify-java-desktop-clients-about-changes-from-server

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