我不清楚如何使用socket.io-emitter(服务器到服务器) [英] i am unclear of how to use socket.io-emitter (server to server)

查看:501
本文介绍了我不清楚如何使用socket.io-emitter(服务器到服务器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我初始化和发出信号的方式,但是我没有发现任何错误,也没有侦听服务器,接收任何事件.

Below is how i initialize and emit but i dont find any errors nor do my server listening, receives any events.

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'})

我尝试了许多变化,有人可以启发我如何调试它吗?

i tried many variations, can someone enlighten me how can i debug this ?

ive也尝试在对象之前添加redis href.

ive tried to add a redis href before the object as well.

推荐答案

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

I found the error, the issue was with the pub and sub sockets.

这是解决方案:

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 }));

这是问题所在:

我不是使用未定义的密码来检查密码,而是 创建了另一个客户端,将其设置为默认值更加容易.

Instead of having it at undefined for the checking of password, I created another client, it was easier to set it to default.

请告诉我是否可以改进我的代码.谢谢.

Please do let me know if I could improve my code. Thank you.

这篇关于我不清楚如何使用socket.io-emitter(服务器到服务器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆