Get the client's IP address in


When using socket.IO in a Node.js server, is there an easy way to get the IP address of an incoming connection? I know you can get it from a standard HTTP connection, but is a bit of a different beast.

5/4/2015 3:17:51 PM

Accepted Answer

Okay, as of 0.7.7 this is available, but not in the manner that lubar describes. I ended up needing to parse through some commit logs on git hub to figure this one out, but the following code does actually work for me now:

var io = require('').listen(server);

io.sockets.on('connection', function (socket) {
  var address = socket.handshake.address;
  console.log('New connection from ' + address.address + ':' + address.port);
9/25/2015 2:19:39 PM

for 1.0.4:

io.sockets.on('connection', function (socket) {
  var socketId =;
  var clientIp = socket.request.connection.remoteAddress;


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow