How get IP address before connecting?
var webSocketServer = new WebSocketServer.Server({port: 8081, verifyClient: function(info, callback) { });
The info object should contain a reference to the request object.
info.request ?
info.req where req is the full request object.
I don't find IP address client on server -
console.log(info.req);
console.log(util.inspect(info, false, null));
Been at this _exact_ spot for 2 hours now! Google, SO, WS docs, everything. :weary:
info.req.remoteAddr is undefinedinfo.req.connection.remoteAddr is undefinedinfo.req.socket.remoteAddr is undefinedinfo.req.connection.socket is undefinedinfo.req.socket._socket is undefinedinfo.req.socket.upgradeReq is undefinedEDIT: My bad... Should be .remoteAddress not .remoteAddr
It should be info.req.connection.remoteAddress but if you are using a reverse proxy that is the proxy address.
IKR? If req is a copy of the Node.js http.ClientRequest, remoteAddr should be at req.connection.remoteAddr, except it's not...
new ws.Server({
server, // (server instanceof http.Server) === true
verifyClient(info) {
console.log(info.req.connection.remoteAddr);
return true;
},
});
Yields
on connection.
Can someone reproduce?
EDIT: Should be remoteAddress not remoteAddr...
Since when was it connection.remoteAddr? The Node.js docs clearly state connection.remoteAddress
Oh damn... I'm embarrassed now! Sorry. My bad. I have been reading that as remoteAddr, even when @Ipinca commented above. So sorry...
lpinca - Very Thanks You!!!
np.
Most helpful comment
It should be
info.req.connection.remoteAddressbut if you are using a reverse proxy that is the proxy address.