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