3

Lets say we have a web based application where users login to their own channel. And our server manages and maintains a list of users, and their current ip addresses.

When someone logs in, is it possible for each client to receive a notification of this users login? Equally if someone logs out, a similar notification would be generated. (Useful for maintaining a list of online friends).

IE: is it possible for the server to send some sort of packet to each client, or for the client machine (the guy who logs in/out) to communicate to all other client machines.

Just looking for thoughts on the subject. If you know a good framework for this sort of functionality id like to hear about it. AJAX or JQuery spring to mind, but are these technologies useful for this sort of thing?

Thanks guys...

Donal.Lynch.Msc
  • 3,001
  • 12
  • 41
  • 71

3 Answers3

2

Yes. Comet is meant for this. Here is a jQuery plugin. And this answer can be useful. Or you can simply ajax-poll the server at a given rate and it will serve changes.

That's from on the client side. The server is simply serving the current state it holds (either in memory, or in a database). However one should give special attention to the case when multiple servers work in a cluster. In that case they should either replicate their memory, or use a "hard" storage (database), so that changes are propagated to all nodes.

Community
  • 1
  • 1
Bozho
  • 554,002
  • 136
  • 1,025
  • 1,121
2

Kwwika is library for doing just this sort of thing: http://kwwika.com/

"Want your Web page to update instantly when stuff changes? Just add a KwwikTag. Then the moment you type something into your KwwikScreen (or publish it via the Kwwika API) everyone will see it. No reloading, no polling – the new information appears immediately on the page."

RichieHindle
  • 244,085
  • 44
  • 340
  • 385
  • isn't it implemented using polling as well? – Bozho Sep 10 '10 at 16:51
  • From the site: *"Kwwika does not (normally) rely on polling, but instead uses much more efficient asynchronous push of data"* [...] *"The most efficient supported encapsulation method is used for each connected client (Kwwika supports six different methods)."* – RichieHindle Sep 10 '10 at 16:53
2

It's possible, but if you think about it, it would be difficult to have it scale well. You could use something like node.js, which is a JavaScript-based http server, very simple (though you could use a normal apache/etc server, just beware of scaling with connections). then you might use flash, web sockets or long polling on the client side to check if anyone has logged in (have a thread-safe queue, database table or flat logfile to hold records of recent log-ins)

Long polling is simply making a request via Ajax to the server, which doesn't respond until something happens (ie, a login) or a timeout occurs.