Ws: How can I get the client ip address?

Created on 28 Jul 2014  Â·  5Comments  Â·  Source: websockets/ws

I would like to know the web socket client's ip address when the WebSocketServer get the connection event. How can I do that?

Most helpful comment

wss.on('connection', function(ws) {

logger.info('New websocket connection from %s:%d', ws._socket.remoteAddress, ws._socket.remotePort);

}

All 5 comments

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.');
    });
Was this page helpful?
0 / 5 - 0 ratings

Related issues

cmnstmntmn picture cmnstmntmn  Â·  4Comments

dcflow picture dcflow  Â·  4Comments

nodesocket picture nodesocket  Â·  4Comments

HanHtoonAung picture HanHtoonAung  Â·  3Comments

binarykitchen picture binarykitchen  Â·  5Comments