本文介绍了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
广播到给定房间中的所有套接字,除了广播到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之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!