I would like to know how to get the IP of a user when they connect to the server n socket.io. I have tried using this code which is supposed to log the connection address and port like this:
var io = require('socket.io')(serv, {});
io.sockets.on('connection', function(socket) {
var address = socket.handshake.address;
console.log('New connection from ' + address.address + ':' + address.port);
socket.on('request', function(data) {
console.log('Request Sent')
length = data.length
if (data.request == 'sessionID') {
socket.emit('sendSessionID', {
id: generateSessionID(length)
});
console.log('Sent session ID')
}
if (data.request == 'players') {
}
});
});