socket.on('data', function(data)
{
console.log(socket.remoteAddress + ":" + socket.remotePort);
}
socket.on('close', function()
{
console.log(socket.remoteAddress + ":" + socket.remotePort);
}
The log from the data handler displays 127.0.0.1:8000.
The log from the close handler displays undefined:undefined.
I am trying to keep a list of connected sockets using IP:Port as the key. If I don’t know which one closed, how can I remove it from the list? How can I get the IP:Port of the closed socket after it’s closed?
This is how I’m keeping track of the clients:
Much thanks to mscdex in the Node.js IRC channel for suggesting this solution!