Socket.io发送消息含义
2016-03-29 13:54
423 查看
仅作收藏:转自博客园 若相忆;
订阅发布模式
// send to current request socket client socket.emit('message', "this is a test"); // sending to all clients, include sender io.sockets.emit('message', "this is a test"); // sending to all clients except sender socket.broadcast.emit('message', "this is a test"); // sending to all clients in 'game' room(channel) except sender socket.broadcast.to('game').emit('message', 'nice game'); // sending to all clients in 'game' room(channel), include sender io.sockets.in('game').emit('message', 'cool game'); // sending to individual socketid io.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); })
浏览器的全局属性 window.WebSocket
![](https://images2015.cnblogs.com/blog/921378/201603/921378-20160330100043051-1238532091.jpg)
相关文章推荐
- scala发送消息到kafka示例
- 【LeetCode编程学习(C语言)】2.Add Two Numbers
- java中File类的使用方法
- Oracle MERGE INTO 语句
- Atom使用心得 - 21世纪的编辑器
- 确定两串乱序同构
- oracle 备库归档自动删除脚本
- win7-64bit 安装Python3.5
- Android之网络编程
- Redis分布式客户端-Redisson介绍
- 2016-3-29 linux基础学习——vim编辑器的使用
- Android 自定义权限的使用以及遇到的问题
- iOS 对网络视频采集视频截图
- spring mvc 的 resources 注解 用来处理静态文件
- 当当网的内部框架开源策略案例分享
- 积分图像
- Linux内核分析 读书笔记 (第十八章)
- leetcode 3. Longest Substring Without Repeating Characters
- QPS PV
- 别再用print来调试啦:logging模块超简明指南