-1

I have a Ruby on Rails 3 application, and I want to be able to see a list of who is currently online. For example user1, IP address, and country. I then want to be able to open a chat / push messages to this user until they leave my site.

How can I accurately monitor who is currently on the site and instantly remove the user from the list when they leave?

I then can talk to them via faye pub/sub.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rick
  • 463
  • 5
  • 23

2 Answers2

1

How can I accurately monitor who is currently on the site and instantly remove from list when they leave?

Well using HTTP you can not do this "instantly" in a browser. Almost all solutions I see use a heartbeat technique. Every X seconds, a request is sent from the browser (using Ajax), that tells if the user is online. If you haven't heard from the user in x heartbeats, you regard the user as disconnected - even Facebook uses this, it seems. I will recommend you to drop your requirement for instant, unless it's really important.

Another approach is to implement Flash or Silverlight, to make a socket connection to the server. But the demand on the server is high, and if many people is on your site, you will run into trouble with ports and so on.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jesper Blad Jensen
  • 2,751
  • 17
  • 16
  • The reason that you cannot do this "instantly" is that HTTP(S) is stateless. So, at any given moment the server can only know about the last request from any given client. This is the correct solution. – Midwire Jul 04 '11 at 15:19
0

I think this is not so much related with Ruby on Rails... but this is very hard to implement in HTTP with a scripting language only. The server does not know whether a user has closed the browser or not. The server just sends the requested page data to the user and closes the connection.

You would rather have to integrate Ajax or Flash to make things easier. I have seen some people developing chat programs with Flash, and it seems to work much better than any other Ajax-implemented chat programs.

Chat is very unfavorable in a web browsing context, since the page will be reloaded as the user clicks a link. If you are thinking about building an application that only supports a chat feature, you probably want to look something other than Ruby on Rails. For example, Node.js will be a good one.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user482594
  • 16,878
  • 21
  • 72
  • 108
  • Not really answered the question. How can i accurately monitor who is currently on the site and instantly remove from list when they leave ? I can do the chat no problem with faye. thanks anyway – rick Jul 03 '11 at 10:22