Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

Now a days real time updates are common in most popular sites which have heavy usages.

I'm wondering how do these "real time updates" work? I'm just looking for a general bird's view perspective. I suspect that the JS can't be calling the server every X seconds for an update and then appending that to the <ul>. Is a notification sent from the server went to pull more content?

Would be great if there is a simple how to article that explains this with a demo?

share|improve this question
5  
Two words: web sockets – Dennis May 30 '12 at 1:35
1  
That's HTML5. – Derek 朕會功夫 May 30 '12 at 1:37
18  
One word: WebSocket – Šime Vidas May 30 '12 at 1:37
    
You might be interested in this answer: stackoverflow.com/questions/10782058/… – Alessandro Alinone May 30 '12 at 12:30

Stack Overflow is using Web Sockets for real time updates. If you take a look in the source code (line 35), you would see:

StackExchange.ready(function () {
    StackExchange.realtime.init('ws://sockets.ny.stackexchange.com');
    StackExchange.realtime.subscribeToInboxNotifications();
    StackExchange.realtime.subscribeToReputationNotifications('1');
});

But note that some Opera versions does not support WebSocket. (not until Opera 10.70)

However Facebook does not seem to use Web Sockets, and I think they are just using simple XHR with a technique called long polling, which the server holds on to the connection until there is new information, and then the server will response to the request. If you open up the developer tools you can see that there is always one request which has a status of pending.

It is indeed, sending a request every ~60 seconds.

share|improve this answer

It seems that Twitter also uses simple XHR (1 minute intervals) for their "real time updates".

share|improve this answer

Facebook uses long polling/Comet. So it makes a connection and waits for a response, if no response, then it times out and tries again. The timeout is around 40 secs. That's how it does most of the instant updating. However they use a combination of techniques. More on long polling here.

http://en.wikipedia.org/wiki/Comet_(programming)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.