简体   繁体   English

如何获取客户端服务器端更新的跟踪?

[英]How to get a track of server side updates client side?

The scenario is that I am having a piece of code written in Javascript that keeps refreshing after a short interval of time and keep matching with a file on the server side and if there is a change in the file on the server side it downloads the updated file. 方案是我有一段用Javascript编写的代码,在短时间内保持刷新并与服务器端的文件保持匹配,如果服务器端的文件发生了变化,则会下载更新的文件。 But because it keep refreshing all the time so it may create a huge traffic on the server on later run. 但是因为它一直在不断刷新,所以它可能会在以后的运行中在服务器上产生巨大的流量。

So i want to know that is there any kind of mechanism here (like push notifications i have heard though not sure about it) that can give a notification to the client when the file on the server side updates? 所以我想知道这里有什么样的机制(比如我听过但不确定的推送通知),当服务器端的文件更新时,它可以通知客户端? So that client side may be free from creating unnecessary requests. 这样客户端就可以免于创建不必要的请求。

Given that my server side code is written in Java. 鉴于我的服务器端代码是用Java编写的。

I think what you're looking for is websockets. 我认为你要找的是websockets。 These enable two way communication between a server and a (web) client. 这些实现了服务器和(Web)客户端之间的双向通信。 This way, you can send the push notifications to your client. 这样,您就可以将推送通知发送给您的客户端。

There is some more information here about websockets (the client side) and here is the java documentation. 有一些更多的信息在这里有关的WebSockets(客户端),并在这里是Java文档。

Consider researching Websockets and Server-sent events . 考虑研究WebsocketsServer发送的事件 I have not used any of them with Java but I'm sure that you can find a nice library. 我没有使用Java中的任何一个,但我相信你可以找到一个很好的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM