Asynchronous in Socket.io
I use 2 variables online (to count the number of online people currently) and total variable (count the total number of people visited). The problem is that when I reload page continuously online variable has not decreased, it has increased.
io.on('connection', function(sock) {
sock.on('disconnect', function() {
sock.broadcast.emit('Client-disconnect', --online);
})
io.sockets.emit('Client-connection',{ onl: ++online, tol: ++total });
}