Node.js核心模块-net
net.Socket 类
socket.remotePort
访问服务器的远程端口
const http = require('http'); const server = http.createServer((req, res) => { console.log(`端口是${req.socket.remotePort}`) }).listen(3002)
socket.remoteAddress
访问服务器的远程ip地址
const server = http.createServer((req, res) => {
console.log(`端口是${req.socket.remoteAddress}`)
}).listen(3002)