websockets / ws

Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
MIT License
21.55k stars 2.42k forks source link

Client IP Not working #1279

Closed bioinfo35 closed 6 years ago

bioinfo35 commented 6 years ago

const WebSocket = require('ws');

const wsss = new WebSocket.Server({ port: 2000 });

wsss.on('connection', function connection(ws, req) { console.log(req); const ip = req.connection.remoteAddress; });

i get req is not defined

Description

Reproducible in:

version: Node.js version(s): OS version(s):

Steps to reproduce:

1. 2. 3.

Expected result:

Actual result:

Attachments:

lpinca commented 6 years ago

Update ws to version 3.0.0 or greater.

bioinfo35 commented 6 years ago

i am using ws v 4.0 here is screenshot https://www.screencast.com/t/ESZdbNg5 i tested it on windows and ubuntu

lpinca commented 6 years ago

npm info queries the public registry, so you get the latest version. Run npm ls ws from the root of your project to find out what version of ws you are actually using.

If you are on ws@<3.0.0, use ws.upgradeReq instead of req.

bioinfo35 commented 6 years ago

Thank You @lpinca