I'm using Node.js with https://github.com/websockets/ws.
I'm trying to store the users remoteAddress in a temporary socket variable. I can access this variable by:
socket.upgradeReq.connection.remoteAddress
The problem is, where in the world did remoteAddress come from? The variable 'remoteAddress' is not even found in any of the WS node_plugin files in the lib directory. (I used Notepad++ to search through every file.)
The only reason I came about finding access to this variable is from this topic: How to get client IP address using websocket (einaros / ws) lib in node.js?
Heck, even when displaying console.log(self.upgradeReq.connection);
in my console I still cannot find it!
Images of the object console list:
Where in the world? Am I missing something?
It comes Node.js's built-in net
module. Here's how to trace it:
The ws documentation refer to upgradeReq
as "The HTTP request that initiated the upgrade". Glancing through the ws
code makes it clear that it uses Node.js's built-in http
library for handling HTTP requests.
The Node.js http
request documentation says that http.ClientRequest.connection
is a reference to a given request's underlying TCP socket
.
Node.js's TCP code is in the net
library. The net
docs document socket.remoteAddress
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With