如何在具有多个节点和socket.io-redis的socket.io中检查套接字是否处于活动状态(已连接) [英] How to check socket is alive (connected) in socket.io with multiple nodes and socket.io-redis

查看:238
本文介绍了如何在具有多个节点和socket.io-redis的socket.io中检查套接字是否处于活动状态(已连接)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将socket.io与多个节点,socket.io-redis和nginx一起使用.我遵循此指南: http://socket.io/docs/using-multiple-nodes/

I am using socket.io with multiple nodes, socket.io-redis and nginx. I follow this guide: http://socket.io/docs/using-multiple-nodes/

我正在尝试做:在一个函数(服务器站点)上,我想通过socketid查询此套接字是已连接还是已断开

I am trying to do: At a function (server site), I want to query by socketid that this socket is connected or disconnect

我尝试了io.of('namespace').connected[socketid],它仅适用于当前进程(这意味着它只能检查当前进程).

I tried io.of('namespace').connected[socketid], it only work for current process ( it mean that it can check for current process only).

任何人都可以帮助我吗?感谢您的进阶.

Anyone can help me? Thanks for advance.

推荐答案

如何使用我尝试过的socketid检查套接字是否处于活动状态(已连接) namespace.connected [socketid],仅适用于当前进程.

How can I check socket is alive (connected) with socketid I tried namespace.connected[socketid], it only work for current process.

正如您所说,单独的进程意味着套接字仅在它们首次连接的进程上注册.您需要使用 socket.io-redis 连接所有节点在一起,并且您可以做的是在每次客户端连接/断开连接时广播事件,以便每个节点都具有所有客户端的更新的实时列表.

As you said, separate process means that the sockets are only registered on the process that they first connected to. You need to use socket.io-redis to connect all your nodes together, and what you can do is broadcast an event each time a client connects/disconnects, so that each node has an updated real-time list of all the clients.

这篇关于如何在具有多个节点和socket.io-redis的socket.io中检查套接字是否处于活动状态(已连接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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