2017-06-12 103 views
0

請問,如何使用uWebSockets獲取發件人IP地址?使用uWebSockets獲取IP地址

const wss = new uws.Server({ 
    server: server, 
    perMessageDeflate: false 
}); 

wss.on(`connection`, ws => { 
    ws.remoteAddress = ws.upgradeReq.connection.remoteAddress; 
    console.log(`user connected: `, ws.remoteAddress); 
}); 

用戶連接是undefined

回答

0

請試試這個:

wss.on(`connection`, ws => { 
ws.remoteAddress = ws._socket.remoteAddress; 
    console.log(`user connected: `, ws.remoteAddress); 
}); 

您也可以登錄到ws._socket知道它是什麼。