开发者

How can a Node.js Socket Server know which IP or domain that the client connect to?

开发者 https://www.devze.com 2023-01-12 10:13 出处:网络
How can I know which IP/hostname the client connect to in node.js TCP Server? var server = net.createServer(functio开发者_开发问答n (stream) {

How can I know which IP/hostname the client connect to in node.js TCP Server?

var server = net.createServer(functio开发者_开发问答n (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');

Thanks


Got the ans: We can use stream.address() to get the port and host the client connect to.

0

精彩评论

暂无评论...
验证码 换一张
取 消