When someone connects to the node server, I keep an array with all the sockets. That way I can broadcast messages to everyone whenever that is needed or loop through the use
You already have the socket, because the disconnect handler is declared within the 'connection' event scope. Try removing the parameter you are passing to the 'disconnect' handler, you should be able to work with the socket parameter from the connection handler.
io.sockets.on('connection', function(socket) {
allClients.push(socket);
socket.on('disconnect', function() {
console.log('Got disconnect!');
var i = allClients.indexOf(socket);
delete allClients[i];
});
});
Apart from that, you don't need a socket array to broadcast, you can use rooms to group sockets and broadcast to all the sockets inside that room.