nodejs-websocket icon indicating copy to clipboard operation
nodejs-websocket copied to clipboard

how to get client ip address with nodejs-websocket?

Open youaresherlock opened this issue 5 years ago • 1 comments

how can a server get the ip address from the client?

youaresherlock avatar Mar 13 '19 11:03 youaresherlock

The remote address should be available via the conn.socket.remoteAddress property. For example:

const ws = require('nodejs-websocket');
const LISTEN_ADDRESS = '0.0.0.0';
const LISTEN_PORT = 8080;

let server = ws.createServer(function(conn) {
  let rAddr = conn.socket.remoteAddress;
  let rPort = conn.socket.remotePort;
  console.log(`New connection from ${rAddr}:${rPort}`);
}).listen(LISTEN_PORT, LISTEN_ADDRESS);

jdgregson avatar Aug 07 '19 19:08 jdgregson