I would like to know the web socket client's ip address when the WebSocketServer get the connection event. How can I do that?
wss.on('connection', function(ws) {
logger.info('New websocket connection from %s:%d', ws._socket.remoteAddress, ws._socket.remotePort);
}
Thanks! It worked.
But I found that when the websocket is closed, there is no ws._socket.remoteAddress then. I don't know why.
Liu,
when you open a "ws", a part of the memory is used for the information
related to it. When you close it, its not available/allocated anylonger.
On Thu, Sep 11, 2014 at 1:50 PM, Liu Xing [email protected] wrote:
But I found that when the websocket is closed, there is no
ws._socket.remoteAddress then. I don't know why.wss.on('close', function (ws) {
logger.info('New websocket connection from %s:%d', ws._socket.remoteAddress, ws._socket.remotePort);}}—
Reply to this email directly or view it on GitHub
https://github.com/einaros/ws/issues/338#issuecomment-55253104.
@dkdndes Yes. But I found that websocket can do that.
connection.on('close', function(reasonCode, description) {
console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');
});
Most helpful comment
wss.on('connection', function(ws) {
}