V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
BeginMan
V2EX  ›  Node.js

关于 socket.io 负载均衡问题

  •  
  •   BeginMan · 2015-07-09 11:36:31 +08:00 · 4278 次点击
    这是一个创建于 3515 天前的主题,其中的信息可能已经有所发展或是发生改变。

    关于socket.io 负载均衡问题,参考官网Using multiple nodes:http://socket.io/docs/using-multiple-nodes/, 我设置如下:

    var io = require('socket.io').listen(8891);
    
    var port=6379;
    var host='localhost';
    var pwd = '******';
    
    var redis = require('redis').createClient;
    var adapter = require('socket.io-redis');
    var pub = redis(port, host, { auth_pass: pwd });
    var sub = redis(port, host, { detect_buffers: true, auth_pass: pwd });
    io.adapter(adapter({ pubClient: pub, subClient: sub }));
    

    关于这个adapter 总是报错:

    io.adapter(adapter({ pubClient: pub, subClient: sub }));
       ^
    TypeError: undefined is not a function
    at Object.<anonymous> (/home/team/project/ylx/sync-svc/sync-server_8891.js:18:4)
    at Module._compile (module.js:462:26)
    at Object.Module._extensions..js (module.js:480:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:503:10)
    at startup (node.js:132:16)
    at node.js:817:3
    

    我的socket.io版本0.9.17,其他版本见下方:

    ├─┬ hiredis@0.3.0
    │ ├── bindings@1.2.1
    │ └── nan@1.5.3
    ├── redis@0.12.1
    ├─┬ socket.io@0.9.17
    │ ├── base64id@0.1.0
    │ ├── policyfile@0.0.4
    │ ├── redis@0.7.3
    │ └─┬ socket.io-client@0.9.16
    │   ├─┬ active-x-obfuscator@0.0.1
    │   │ └── zeparser@0.0.5
    │   ├── uglify-js@1.2.5
    │   ├─┬ ws@0.4.32
    │   │ ├── commander@2.1.0
    │   │ ├── nan@1.0.0
    │   │ ├── options@0.0.6
    │   │ └── tinycolor@0.0.1
    │   └── xmlhttprequest@1.4.2
    └─┬ socket.io-redis@0.1.4
      ├── debug@0.7.4
      ├─┬ msgpack-js@0.3.0
      │ └─┬ bops@0.0.7
      │   ├── base64-js@0.0.2
      │   └── to-utf8@0.0.1
      ├── redis@0.10.1
      ├─┬ socket.io-adapter@0.3.1
      │ ├─┬ debug@1.0.2
      │ │ └── ms@0.6.2
      │ ├── object-keys@1.0.1
      │ └─┬ socket.io-parser@2.2.2
      │   ├── benchmark@1.0.0
      │   ├── component-emitter@1.1.2
      │   ├── debug@0.7.4
      │   ├── isarray@0.0.1
      │   └── json3@3.2.6
      └── uid2@0.0.3
    

    对于此类问题求解决方案~

    2 条回复    2015-07-09 12:04:35 +08:00
    BeginMan
        1
    BeginMan  
    OP
       2015-07-09 12:02:18 +08:00
    刚才测试了下,还是版本的问题。
    BeginMan
        2
    BeginMan  
    OP
       2015-07-09 12:04:35 +08:00
    如果是不升级的话 socket.io 0.9.x 就不能multiple nodes 么????
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1082 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 18:45 · PVG 02:45 · LAX 10:45 · JFK 13:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.