how to get client ip address with nodejs-websocket? #57

Open
opened 2019-03-13 11:46:42 +00:00 by youaresherlock · 1 comment
youaresherlock commented 2019-03-13 11:46:42 +00:00 (Migrated from github.com)

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

how can a server get the ip address from the client?
jdgregson commented 2019-08-07 19:06:18 +00:00 (Migrated from github.com)

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);
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);
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: sitegui/nodejs-websocket#57
No description provided.