Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get client ip address in socket.io 2.0.3?

I am currently using socket.io v2.0.3 in node.js server and can't find a way to get client's IP address.

There are numerous of tips & tricks all around stackoverflow but they are outdated and not working anymore.

like image 420
Darker Avatar asked Jan 04 '23 13:01

Darker


1 Answers

It is in the socket.handshake

{
  headers: /* the headers sent as part of the handshake */,
  time: /* the date of creation (as string) */,
  address: /* the ip of the client */,
  xdomain: /* whether the connection is cross-domain */,
  secure: /* whether the connection is secure */,
  issued: /* the date of creation (as unix timestamp) */,
  url: /* the request URL string */,
  query: /* the query object */
}

See this link

Edit: turns it it might have changed to socket.request.connection.remoteAddress, see this link.

Edit2 : Issue could be related to Client and Server version unaligned.

like image 93
Eric Avatar answered Jan 15 '23 14:01

Eric