Is it possible to get the socket.id of the client that has disconnected? The following code gives me undefined for socket.id
Node.js Code
io.sockets.on('connection', function() {
socket.on('disconnect', function(socket) {
console.log(socket.id);
});
});
The callback function that
io.sockets.ontakes as its second argument is supposed to take one argument: the socket. Yours doesn’t, so the socket on the second line’ssocket.onis undefined.And the callback for
socket.onisn’t given any arguments, so thesocketin that function is also undefined.The code should work if you move the socket parameter from the second function declaration to the first: