I have read here that I can get client's IP in node.js with
socket.request.connection.remoteAddress
for example:
var socket = io.listen(server);
socket.on('connection', function(client){
var client_ip_address = socket.request.connection.remoteAddress;
}
But when I use this solution I get the error message "Cannot read property 'connection' of undefined" which means that socket.request is undefined.
Why would that be the case?
I have also tried another option found on the same page:
var sHeaders = socket.handshake.headers;
console.info('[%s:%s] CONNECT', sHeaders['x-forwarded-for'], sHeaders['x-forwarded-port']);
but this just outputs
[undefined:undefined] CONNECT