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 -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -