首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iisnode获取remoteAddress

iisnode获取remoteAddress
EN

Stack Overflow用户
提问于 2015-11-26 21:49:35
回答 1查看 249关注 0票数 0

尝试让iisnode和socket.io正常工作(一直在linux上运行得很好)。我正在使用Sticky会话,以便能够使用多个处理器。

现在,当通过iisnode运行时,我在从客户端获取远程ip时遇到了问题。

看起来connection.headers是空的。我遗漏了什么?

代码语言:javascript
复制
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 }时,您无法访问标题。

EN

回答 1

Stack Overflow用户

发布于 2016-01-22 01:22:56

不能100%确定这是否是您的问题,但是对于IISNode,您需要明确地告诉它您将在Web.config中使用Socket.io。

您可以在Web.config中的两个位置执行此操作:

<handlers> element中的

代码语言:javascript
复制
<handlers>
  <!-- Change the path attribute to your main file-->
  <add name="iisnode-socket.io" path="app.js" verb="*" modules="iisnode" />
</handlers>

为Socket.io添加额外的URL重写规则

代码语言:javascript
复制
<rule name="SocketIO" patternSyntax="ECMAScript">
  <match url="socket.io.+" />

  <!-- Change the url attribute to your main file-->
  <action type="Rewrite" url="app.js"/>
</rule>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33940377

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档