【问题标题】:i am unclear of how to use socket.io-emitter (server to server)我不清楚如何使用 socket.io-emitter (服务器到服务器)
【发布时间】:2018-01-08 08:59:42
【问题描述】:

以下是我如何初始化和发出,但我没有发现任何错误,我的服务器也没有监听,接收任何事件。

const io = require('socket.io-emitter')({
  host: 127.0.0.1,
  // path: do i need this ?
  port: redisUri.port,
  pub: pub, // is the key required to be the same as the app ?
  sub: sub, // is the key required to be the same as the app ?
});

io.emit('test', 'test'})

我尝试了很多变体,有人能告诉我如何调试吗?

我也尝试在对象之前添加一个 redis href。

【问题讨论】:

    标签: socket.io socket.io-1.0 socket.io-redis


    【解决方案1】:

    我发现了错误,问题出在 pub 和 sub 套接字上。

    解决办法如下:

    var pub = redisPassword ? redis.createClient(6379, localhost, {return_buffers: true, auth_pass: redisPassword}) : undefined;
    var sub = redisPassword ? redis.createClient(6379, localhost, {detect_buffers: true, return_buffers: true, auth_pass: redisPassword}) : undefined;
    socketio.adapter(require('socket.io-redis')({ host: localhost, port: 6379, pubClient: pub, subClient: sub }));
    

    这就是问题所在:

    我没有将它设置为 undefined 来检查密码,而是 创建了另一个客户端,将其设置为默认值更容易。

    如果我可以改进我的代码,请告诉我。谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-29
      • 2013-01-30
      • 2018-10-06
      • 2018-08-21
      • 2016-08-20
      • 1970-01-01
      • 2018-11-09
      相关资源
      最近更新 更多