node.js - How to handle asynchronous in Javascript? -


asynchronous in socket.io

i use 2 variables online (to count number of online people currently) , total variable (count total number of people visited). problem when reload page continuously online variable has not decreased, 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 }); } 

the connections being left open not closed when page either refreshed or closed. listen page events able close connection before page removed:

window.onbeforeunload = function(e) { sock.disconnect(); };


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -