Node.js Socket Server 如何知道客户端连接到哪个 IP 或域?
问题描述:
如何知道客户端在 node.js TCP Server 中连接到哪个 IP/主机名?
How can I know which IP/hostname the client connect to in node.js TCP Server?
var server = net.createServer(function (stream) {
// The server is behind a firewall,
// how can I know how the client connect to this server?
console.log(stream.localAddress);
});
server.listen(21, '0.0.0.0');
谢谢
答
得到答案:我们可以使用 stream.address() 来获取端口和主机连接到的客户端.
Got the ans: We can use stream.address() to get the port and host the client connect to.