title: In socket.io with node.js, how can I determine the server IP of a specific connection?
body: <p>Ultimately, the goal here is to handle DNS round robin with socket.io, to coordinate different connections (socket.io and jQuery ajax) so they go to the same server when one name maps to multiple servers.</p>
  
  <p>With this code, I am able to find the <strong>client</strong>-side IP address of an incoming websockets connection:</p>
  
  <pre><code>var app = express();
     ...
  var server = http.createServer(app);
     ...
  var io = socketio.listen(server);
  io.on('connection', function(socket) {
    var addr = socket.handshake.address;
    logger.info("Just got incoming connection from client " + addr.address
                + ":" + addr.port);
  </code></pre>
  
  <p>But how can I find the <strong>server</strong>-side IP address of this socket?  I would like to send the server-side IP address to the client (with <code>socket.emit('serverSideIp': &lt;server-IP&gt;)</code>) so for diagnostic purposes we can track which specific IP address is in use.  Also, when a socket.io connection fails and goes to a different IP, I want to redirect client-side AJAX requests to that IP so the client is not talking to different servers at the same itme.</p>
  
  <p><strong>EDIT:  <a href="https://stackoverflow.com/questions/3653065/get-local-ip-address-in-node-js">Get local IP address in node.js</a> does not answer my question.</strong>  Answered there is, "What is my list of IP addresses."  My question is, "Given a specific socket, what is the local address (IP and port) of that specific socket" which cannot be answered on a multi-homed host by getting a list of addresses from the OS.  In Java or C# it is trivial to get the local and remote port and IP address of a socket.  How do you do this in node.js for a socket.io "socket" connection?</p>