node.js - How do to do online and offline in socket.io? -


how online , offline in socket io? need redis store session or mongodb?

my attempt serverside

io.on('connection', function(socket) {   socket.emit('connected', 'online');    socket.disconnect('disconnect', function() {      socket.emit('connected', 'offline');   });  }) 

clientside

 socket.on('connected', function(data) {     $('#useronline').html(data);   }); 

with code above not consistent, shows offline, not

the corrrect way listen when socket disconnect is:

socket.on('disconnect', function () { ...... }); 

and not emit socket inside callback.

for exact answer need know how make disconnection (server or client side) , should receive information, himself or others clients?


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -