Socket.io的自述文件包含以下示例:
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广播在给定房间中所有的插座, 除外 到它被调用而插座io.sockets.in广播在给定房间内的所有插座。
socket.broadcast.to
io.sockets.in