// send to current request socket clientsocket.emit('message', "this is a test");// sending to all clients, include senderio.sockets.emit('message', "this is a test");// sending to all clients except sendersocket.broadcast.emit('message', "this is a test");// sending to all clients in 'game' room(channel) except sendersocket.broadcast.to('game').emit('message', 'nice game');// sending to all clients in 'game' room(channel), include senderio.sockets.in('game').emit('message', 'cool game');// sending to individual socketidio.sockets.socket(socketid).emit('message', 'for your eyes only');// 进入一个房间socket.join('room'); // 离开一个房间socket.leave('room');
订阅/退订事件
//前端触发订阅/退订事件socket.emit('subscribe',{"room" : "room_name"};socket.emit('unsubscribe',{"room" : "room_name"};//后台处理订阅/退订事件socket.on('subscribe', function(data) { socket.join(data.room);})socket.on('unsubscribe', function(data) { socket.leave(data.room);})
分类:
标签: