试图让 iisnode 和 socket.io 工作(在 linux 上运行良好)。我正在使用 Sticky 会话来使用多个处理器。
现在通过 iisnode 运行时,我在从客户端获取远程 IP 时遇到问题。
看起来 connection.headers 是空的。我错过了什么?
var server = net.createServer({ pauseOnConnect: true }, function (connection) {
// Incoming request processing
// We received a connection and need to pass it to the appropriate
// worker. Get the worker for this connection's source IP and pass
// it the connection.
var remote = connection.remoteAddress; // this returns undefined
var local = connection.localAddress; // this returns undefined
var ip = (remote + local).match(/[0-9]+/g)[0].replace(/,/g, '');
var wIndex = ip % num_processes;
var worker = workers[wIndex];
console.log("Message to work "+ worker+", remote: "+ remote+ ", local: "+ local+", ip: "+ ip +", index: "+ wIndex);
worker.send('sticky-session:connection', connection);
});
更新:使用 pause { pauseOnConnect: true } 时,您无法访问标题。