[英]Get connection IP of WebSocket connection
Once I've opened a web socket like so: 一旦我打开了这样的网络套接字:
m_ws = new WebSocket(127.0.0.1);
Is it possible to get the IP that was just used to open? 是否有可能获得刚刚用于打开的IP? Something like
m_ws._websocket.address
? 像
m_ws._websocket.address
这样的m_ws._websocket.address
?
I've seen numerous examples but none of them worked as I think they apply to WebSocketServer instances. 我已经看过很多例子,但是没有一个例子,因为我认为它们适用于WebSocketServer实例。
Do you use the ws
library ? 你使用
ws
库吗?
If you use ws
to get IP Connection : 如果您使用
ws
来获取IP连接:
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
wss.on('connection', function connection(ws, req) {
const ip = req.connection.remoteAddress;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.