Updating data in a client application, how to avoid polling?

I have a desktop client application that talks to a server application through a REST API using simple HTTP messages. I currently have a customer survey every X minutes, but I would like the data to be updated more often. Is it possible for the server to notify the client of any new data or is it out of scope of what the HTTP server should do? Any thoughts on the best way to approach this would be greatly appreciated. Thanks!

+4
source share
2 answers

You can check the accepted answer for the next post, which describes a very simple example of how to implement Long Polling using php on the server side:

When using Long Polling, your client application launches a request to an HTTP server with an infinite timeout (or very long). Now, as soon as new data appears, the server will find the active connection ready so that it can instantly output the data. In a traditional survey, you will have to wait until the application initiates a new poll, as well as the network timeout, to get to the server before sending new data.

Then, when the data is sent, the connection is closed, but your application should immediately open a new one in order to have a permanent open connection to the server. In fact, there will be a very small gap where there will be no active connection, but this is often negligible in many applications.

+3
source

If you keep the HTTP connection open on the server side, you can send data whenever there is an update, followed by clearing the connection to actually send the data. This can cause problems with the TCP / IP stack if tens of thousands of connections are required.

+1
source

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


All Articles