nodejs-websocket
nodejs-websocket copied to clipboard
how to get client ip address with nodejs-websocket?
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);