views:

48

answers:

1

Summary: is there a daemon that will do postbacks when a user connects/disconnects via TCP, or is it a good idea to write one?

Details: There are a number of questions based around this already; but I believe that this is a different "twist" on it. We're writing a Ruby on Rails web application, and we would like to be able to tell if a user is "online" or "offline", where the following definitions apply:

  • "online" - the user's browser is open and maintaining a TCP connection to one of our servers.
  • "offline" - the user's browser is no longer connected to one of our servers.

What we're thinking is a convenient way of doing this is to run a completely separate "online state" server that each of our users will connect to (exactly once):

  • when a connection is made to the "online state" server, it will postback to our actual RoR site and let it know "this user just logged on".
  • when a connection is lost from the "online state" server, it will postback to our actual RoR site and let it know "this user just logged off".

This methodology seems reasonable and keeps things quite modularized (the online state server, for instance, will be quite simple, which is nice). We're able to write this online state server, but have the following questions:

  1. Any specific problems with the above architecture that we haven't taken into account?
  2. Is there a daemon or application out there that does this already? Why reinvent the wheel, if it has already been written?
  3. Is there a push server out there that offers this functionality (i.e. it maintains connections to the users, but will postback or send notifications upstream to the web servers when a user connects or disconnects?)
A: 

Is this something you envisage users would install on their systems?

If you are looking for a browser based system, WebSockets are probably your only option using something like Socket.IO http://socket.io/.

The node.js socket server provided as part of this project can be found on github: http://github.com/LearnBoost/Socket.IO-node

Node.js is a great platform designed for exactly this problem domain and there are a number of WebSocket servers for node.

Unless your app is entirely ajax based and uses a single parent page, you would need to create a persistent parent frame containing the socket that wraps your application, as each time the user clicks a link the page unloads and reloads, resulting in disconnection and re-connection from the state server.

Toby Hede
No, we were thinking that we would just open a socket connection using JavaScript from the client-side. Thanks for the pointer to WebSockets, that may be useful... right at the moment I'm more interested in the existence of the server-side of the equation, though.
Remi
You are assuming that a user clicking on a link will change the page. With modern AJAX'y web apps, that's not necessarily the case. It certainly does bring up why there aren't hundreds of these state-notification servers already, though.
ChrisInEdmonton
@ChrisInEdmonton - It's a pretty safe assumption, but point taken. I actually had written, unless your app is entirely ajax, but remoded. edited to clarify. I think there aren't many of these systems because it's quite hard to do with current web technologies. Browser-based chat is about the closest we have.
Toby Hede
@Remi - there is a server component to the SocketIO stuff, written in JavaScript for node.js. WebSockets, Flash or similar are the only way to open socket connections from the browser.
Toby Hede