本文介绍了Socket.io 房间之间的区别 broadcast.to 和 sockets.in的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Socket.io 的自述文件包含以下示例:
Socket.io's readme contains the following example:
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.join('justin bieber fans');
socket.broadcast.to('justin bieber fans').emit('new fan');
io.sockets.in('rammstein fans').emit('new non-fan');
});
socket.broadcast.to()
和 io.sockets.in()
有什么区别?
推荐答案
socket.broadcast.to
广播到给定房间内的所有套接字,except 广播到打开的套接字它在 io.sockets.in
广播到给定房间中的所有套接字时调用.
socket.broadcast.to
broadcasts to all sockets in the given room, except to the socket on which it was called while io.sockets.in
broadcasts to all sockets in the given room.
这篇关于Socket.io 房间之间的区别 broadcast.to 和 sockets.in的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!