Send data to the front end when updating

The backend of my web application receives updates from several clients. When such an update occurs, it must be transferred to all other clients.

How can I initiate an update from the server to all web browser clients when updating my backend?

I use JBoss, JSF and Spring framework.

+4
source share
3 answers

I assume that DarthVader has made your interface an (usually) unformatted HTML page of some kind. Something in the browser. If you want all clients to be automatically changed, you have three options:

Comet :
The comet essentially makes AJAX requests that do not have a request timeout limit. You make a request, and it sits there and passes the data through it, as necessary. This can be done using hidden iFrames or standard XMLHTTPRequests (which jQuery can wrap for you). Read more about this method here .

Long survey:
Essentially, you use the javascript setInterval method to continuously poll your server for changes. Just set the interval that executes the standard AJAX GET request to the server, and refresh your page accordingly with each success.

HTML5 WebSockets:
Using any type of event-based backend (Twisted, EventMachine, node.js, etc.) makes WebSockets the perfect solution. It’s just that all customers register in the backend, and when sending from any of these clients, they push changes to all other clients. You can read more (and see a good example) of WebSockets on this page .

+6
source

When you say the front end, you are talking about a stateless http client client.

You cannot push anything from your web servers to http or idle clients.

A "trick" for this is to periodically use asynchronous calls from the outer end to your end.

Think of gmail as you think it shows that you have an email when you receive a new email. You use a browser, sending asynchronous calls to gmail servers, if and when a new message appears, it displays it.

Thus, customers are stateless. use ajax.

it is clear?

+1
source

There are several ways around this. As it should be in the future, follow standards such as Websockets

At the moment, you are stuck in Comet , which essentially sends a request to the server and keeps it open (without signaling the end of the response) and just streaming data through it (Request parking, which they call). Or a periodic survey where you simply execute an AJAX request to the server every predefined interval to ask if the server has something new. It goes without saying that the first work around requires streaming support both on the server and on the browser, but is more effective in most scenarios.

0
source

Source: https://habr.com/ru/post/1388409/


All Articles