2

How Facebook, Google plus or other informations web site, constantly retrieves information from the stream? I suppose there is an asynchronous recovery , but how he gets constantly? It's like an infinite loop?

Which technology is used ?

derekerdmann
  • 17,696
  • 11
  • 76
  • 110
Lez4
  • 55
  • 1
  • 5

1 Answers1

0

There are a few different approaches to displaying updates in near-real time on the web. Here are some of the most common ones:

Short polling

The simplest approach to the problem is to continuously poll the server on a short interval (hence the name). This means that every few seconds, client-side code sends an asynchronous request to the server and displays the result. The downside to this approach is that if updates happen less frequently than the server is queried, the client is doing a lot of work for little payoff. There may also be a slight delay between when the event happens on the server and when the client receives it, based on the polling frequency.

Long polling

The next evolutionary step from short polling is what's known as long polling, where the client-side JavaScript fires off an asynchronous request to the server as soon as the page loads. The server only responds to the request when an update is made, and once the response reaches the client, another request is fired off immediately. The key part of this approach is that the asynchronous request can wait for the server for a long time.

Long polling saves bandwidth and computation time, since the response is only handled when the server has something that changed. It does require more complex server-side logic, but it does allow for near-instant updates on the client side.

This question has a decent sample: How do I implement basic "Long Polling"?

WebSockets

WebSockets are a relatively new technology, and allow for two-way communication in a way that's similar to standard network sockets. The server or client can send messages across the socket that trigger events on the other side of the connection. As nice as this is, browser support isn't as widespread enough to make it a dependable solution.

For the current WebSocket specification, take a look at RFC 6455.

Community
  • 1
  • 1
derekerdmann
  • 17,696
  • 11
  • 76
  • 110