在 0.6 版中,我使用此方法向特定的客户端组发送消息。它将排除 session ID 在 'excludedClients' 数组中的客户端,并发送给所有未排除的客户端。
var excludedClients = [sessionID1, sessionID2, sessionID3];
io.broadcast(msg, excludedClients);
- 此方法在 V0.7 中是否仍然适用?
- 这是最好的方法吗?
希望有人能帮我解决这个问题,似乎任何地方都没有任何关于 Socket IO 的可靠文档,只是在 github 上简要解释了示例页面。
最佳答案
我相信是的;查看 wiki page on 0.6 to 0.7 migration .
如果您的客户可以按逻辑分组,您就可以使用房间。
Rooms
Sometimes you want to put a bunch of sockets in one room, and send a message to them. You can leverage rooms by calling
join
on a socket, and then with the flagsto
andin
:io.sockets.on('connection', function (socket) { socket.join('a room'); socket.broadcast.to('a room').send('im here'); io.sockets.in('some other room').emit('hi'); });
关于javascript - 套接字 IO V0.7 : How to send message to more that one specific client,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7059561/