尝试让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}时,您无法访问标题。
答案 0 :(得分:0)
不是100%确定这是否是您的问题,但是使用IISNode,您需要明确告诉它您将在Web.config中使用Socket.io。
您可以在Web.config中的两个位置执行此操作:
在<handlers>
元素
<handlers>
<!-- Change the path attribute to your main file-->
<add name="iisnode-socket.io" path="app.js" verb="*" modules="iisnode" />
</handlers>
为Socket.io
添加其他网址重写规则<rule name="SocketIO" patternSyntax="ECMAScript">
<match url="socket.io.+" />
<!-- Change the url attribute to your main file-->
<action type="Rewrite" url="app.js"/>
</rule>