javascript - Socket io returns two arrays after singing out and signing back in -


i want socket io send array client side. successful when user first signs in, when user signs out , sign in, socket io sends out 2 of same array. can't seem figure out why this. here code server side:

var object = [];   query.find({     success: function(results){       for(var i=0; i< results.length; i++){         var file = results[i].tojson();         for(var k in file){           if (k ==="javafile"){             for(var t in file[k]){                if (t === "name"){                   temp = file[k][t];                   var getname = temp.split("-").pop();                   object[i] = getname;                 }                               }           }         }       }     }   });  io.on('connection', function(socket){     socket.emit("filename", object);      console.log(object);   }); 

this client side:

socket.on('filename', function(data){ var name = json.stringify(data); console.log(data);  clients[socket.id] = socket; 

when logging out make sure unsubscribe listeners.

something should work :

socket.removealllisteners("filename"); 

alternatively can unsub :

socket.removelistener("filename"); 

ref : google groups discussion

this means next time come along , login there 1 subscription emit to.

related question


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -