尝试让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 }时,您无法访问标题。
发布于 2016-01-22 01:22:56
不能100%确定这是否是您的问题,但是对于IISNode,您需要明确地告诉它您将在Web.config中使用Socket.io。
您可以在Web.config中的两个位置执行此操作:
<handlers> element中的
<handlers>
<!-- Change the path attribute to your main file-->
<add name="iisnode-socket.io" path="app.js" verb="*" modules="iisnode" />
</handlers>为Socket.io添加额外的URL重写规则
<rule name="SocketIO" patternSyntax="ECMAScript">
<match url="socket.io.+" />
<!-- Change the url attribute to your main file-->
<action type="Rewrite" url="app.js"/>
</rule>https://stackoverflow.com/questions/33940377
复制相似问题