sitegui / nodejs-websocket

A node.js module for websocket server and client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to get client ip address with nodejs-websocket?

youaresherlock opened this issue · comments

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

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);