2

I'm trying to get a good way of updating the database for my social network when users disconnect, since the user is no longer on the site there scripts can't be activated to update the database, and emit events to other users on the site, so I'm thinking that I need to some how do this on the server itself, rather than relying on the client side scripting.

right now I'm doing something like this on the server side part of the scripting, (which is loaded by the user still)

socket.on('disconnect', function () { 
socket.broadcast.emit('disconnect', { data : session});
}); 

this then triggers the event on the user side scripting again, and it runs an ajax event to update the MYSQL database, and then trigger another socket event to send to the users notifying that this user disconnected, however this only works if the user closes their browser, but not like shut their laptop, or whatever device, and it also relies on being sent to other users for them to handle it, which I can't have happening.

This is troubling me very much, I need to come up with a solution.

Dylan Cross
  • 5,918
  • 22
  • 77
  • 118
  • I guess you have to listen to the socket timeout/close events, haven't found any solution though. – erenon Feb 18 '12 at 21:39
  • There is even another problem: When you deploy or reboot your server such events might not be fired. Your current approach is very unrealiable. – usr Feb 18 '12 at 21:57
  • Do you have any idea how I could do this a better way? – Dylan Cross Feb 18 '12 at 21:59
  • This might do it for you: http://stackoverflow.com/questions/8648681/nodejs-socket-io-client-doesnt-fire-disconnect-or-close-events-when-the-ser – zallarak Feb 22 '12 at 22:53

1 Answers1

0

Use ajax polling (continually send ajax reqeusts which the server listens to and allows to timeout after 10 seconds) to signal that user is still online. When the server stops receiving requests, the user has logged out.

bts
  • 106
  • 1
  • 3