【发布时间】:2012-02-13 15:11:25
【问题描述】:
我在我的 Node Express 应用程序中使用 Socket.IO,并使用this excellent post 中描述的方法来关联我的套接字连接和会话。在a comment,作者描述了一种向特定用户(会话)发送消息的方法,如下所示:
sio.on('connection', function (socket) {
// do all the session stuff
socket.join(socket.handshake.sessionID);
// socket.io will leave the room upon disconnect
});
app.get('/', function (req, res) {
sio.sockets.in(req.sessionID).send('Man, good to see you back!');
});
似乎是个好主意。但是,在我的应用程序中,我经常会同时向多个用户发送消息。我想知道在 Socket.IO 中执行此操作的最佳方法 - 基本上我需要以最佳性能将消息发送到多个房间。有什么建议吗?
【问题讨论】:
-
您是否找到了一种好方法(在群组/房间聊天中向不同用户发送相同的消息)。 ?