views:

351

answers:

8

I'm using yahoo messenger to chat with my friends. Every time a friend of mine comes online (almost intermediately) YM will notify me. How did Yahoo! (and other companies) do to implement this? As far as I guess, there are some techniques to solve this issue:

  • Pulling: client constantly (500ms duration, maybe) asks server about which users (in the user's list) has just come online and then notify user.

  • Pushing: server determines which users come online and then send a notify to client.

The second approach is much more acceptable. The data of user may contain a list of his friend (who added him to their lists), and the login event raises, server app will send a notify message to all users in this list.

OK, this is only my guess. How was it implemented in reality? Can you tell me?

Thank you.

A: 

Possibly long lived HTTP requests. The IM client calls to a HTTP method on the server but the server doesn't respond until there is an update. At that point it responds with "update" and the IM client then calls another HTTP method to get the update.

Real push isn't possible because many (most?) people on the Internet are behind NAT routers.

Christopher Edwards
+2  A: 

I suggest using Wireshark or any other network traffic inspector to see exactly what's happening on Yahoo Messenger while it's running.

Mike
A: 

It uses a similar technology as Buddy Check, but only lets you know if the user wants you to know. But Buddy Check actually gives you the real truth.

TStamper
A: 

I agree with others that you could just examine the source code or network packets yourself, but think about it from another perspective: which approach makes more sense when you have hundreds of thousands of users and most users probably have just a few dozen "buddies"?

  1. Have hundreds of thousands of users pinging your servers every few seconds = lots of load
  2. Push out updates to clients when their friend's statuses change, which likely happens on a much much smaller scale - a few updates every few minutes.
matt b
A: 

Should be "push architecture".

Servers can't tolerate constant pulling for lots of user.

Ekkmanz
+1  A: 

the server is pushing the data down. the server has a list of your friends, and more importantly a list of whose list you're on. when you sign on, it looks through that second list and pushes a message to each client that's connected. it's pretty simple really. take a look at Pidgin's source code ( pidgin.im ) for more specific implementation details.

Andy Hohorst
A: 

When you login, Yahoo sends (pushes) an 'online event' to everyone on your list who is also online. If the connection is over HTTP, there is a ping/pong exchange between you and Yahoo's server to keep the connection alive (wikipedia) - which allows this push to happen through NATs and whatnot. Else, a TCP/IP connection is kept alive for the duration of your login. If the ping/pong isn't successful (after a number of retries, you would assume), the Yahoo server sends (pushers) messages to all your online friends notifying them of the 'offline event'.

So to answer you question, it is a push.

Catchwa
A: 

I know gtalk over gmail and facebook uses comet. this looks like a good technique but its expensive. this is a good tutotial about in PHP

Gabriel Sosa