大纲
仅作收藏:转自博客园 若相忆;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
socket.emit('message', "this is a test");
io.sockets.emit('message', "this is a test");
socket.broadcast.emit('message', "this is a test");
socket.broadcast.to('game').emit('message', 'nice game');
io.sockets.in('game').emit('message', 'cool game');
io.sockets.socket(socketid).emit('message', 'for your eyes only');
socket.join('room');
socket.leave('room');
|
订阅发布模式
1 2 3 4 5 6 7 8 9 10 11 12
|
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); })
|
####浏览器的全局属性 window.WebSocket