ha
Search…
关于本socket.io中文文档
socket.IO website
1 指南(Guide)
2 文档(Docs)
2.1 概览
2.1.1 啥是Socket.io
2.1.2 Socket.io不是什么
2.1.3 安装
2.1.4 在Node HTTP 服务中使用
2.1.5 在express中使用Socket.io
2.1.6 发送和接收事件
2.1.7 限制自己使用命名空间
2.1.8 发送易失性的消息
2.1.9 发送和获取数据(确认)
2.1.10 广播消息
2.1.111 作为跨浏览器使用websocket
2.2 房间和命名空间
2.3 从0.9迁移版本 migrating_from_0.9
2.4 多路节点使用
2.5 日志和调试
2.6 emit 备忘单
2.7 内部概述
2.8 faq
3 客户端-API(Client-API)
4 服务端-API(Server-API)
Powered By
GitBook
2.1.8 发送易失性的消息
有时可以删除某些消息。 假设您有一个应用程序,显示关键字
bieber
的实时推文。
如果某个客户端尚未准备好接收消息(由于网络速度缓慢或其他问题,或者因为它们通过长轮询连接并处于请求 - 响应周期的中间),如果它没有收到所有推文 与bieber相关的申请不会受到影响。
在这种情况下,您可能希望将这些消息作为易失性消息发送。
Server
1
var
io
=
require
(
'socket.io'
)(
80
);
2
3
io
.
on
(
'connection'
,
socket
=>
{
4
const
tweets
=
setInterval
(()
=>
{
5
// getBieberTweet??
6
getBieberTweet
(
tweet
=>
{
7
socket
.
volatile
.
emit
(
'bieber tweet'
,
tweets
)
8
})
9
},
100
)
10
socket
.
on
(
'disconnect'
,()
=>
{
11
clearInterval
(
tweets
)
12
})
13
})
Copied!
Previous
2.1.7 限制自己使用命名空间
Next
2.1.9 发送和获取数据(确认)
Last modified
2yr ago
Copy link
Contents
Server