当前位置:网站首页>学习太极创客 — MQTT(五)发布、订阅和取消订阅
学习太极创客 — MQTT(五)发布、订阅和取消订阅
2022-06-26 01:56:00 【xuechanba】
学习客户端如何实现发布消息、订阅主题以及取消订阅主题
PUBLISH – 发布消息
有的时候,某个客户端向 MQTT 服务器发布主题新消息的间隔时间比较长,也许几天时间甚至更长,在这种情况下,如果我们客户端订阅了某个主题,它可能要等好长时间,于是为了解决这个问题,就设置了 retainFlag 这个机制,当客户端向服务器端发送的 PUBLISH 报文中,如果 retainFlag 被设置为 ture 时,当客户端订阅了某一主题后,就会马上接收到这个被设置为 ture 的这个报文消息。换句话,MQTT 服务器会将 retainFlag 设置为 true 的 PUBLISH 报文的信息内容给保存起来,保存的目的是无论什么时候,只要有客户端订阅了这个主题消息,服务端就马上将该主题消息发送给客户端。
SUBSCRIBE – 订阅主题
SUBACK – 订阅确认
UNSUBSCRIBE – 取消订阅
下面是实操。
1、客户端连接 MQTT 服务器端
2、客户端订阅主题 chantui
同样,可以点阅多个主题。
3、客户端向名为 chantui 的主题发布消息
点击 publish 后,
边栏推荐
- OpenAPI 3.0 specification - Food Guide
- Which securities company is better and safer to open a mobile stock account?
- Never criticize
- 7 tips to change your life
- Teach you to quickly record sounds on PC web pages as audio files
- 基于 ovarian 数据集 进行生存分析
- 【图像过滤】基于matlab GUI图像过滤系统【含Matlab源码 1913期】
- Little p weekly Vol.10
- Can the main RF circuit be removed for projects that do not need the main RF?
- Fresh graduates talk about their graduation stories
猜你喜欢
GD32 ADC采集电压
音视频与CPU架构
官方零基础入门 Jetpack Compose 的中文课程来啦!
Interviewer: please name four ways to exchange the values of two variables without using third-party variables
OpenAPI 3.0 规范-食用指南
小 P 周刊 Vol.10
Little p weekly Vol.10
Cvpr2022 𞓜 future transformer with long-term action expectation
Deep understanding of distributed cache design
DF reports an error stale file handle
随机推荐
R language survival analysis
IPhone 13 screen stuck black, unable to shut down? How to solve
Digital commodity DGE -- the dark horse of wealth in digital economy
Termux install openssh
What happens when the cloud answer does not display the third-party login button
WPF window centering & change trigger mechanism
College Students' big factory road
请指教同花顺开户选选择哪家券商比较好?网上开户是否安全么?
How to adjust face input size
用指南针交易股票安全吗?指南针是如何交易股票的,需要开户吗
MySQL updates records based on the queried data
How to check and cancel subscription auto renewal on iPhone or iPad
二分查找
arduino字符串转16进制数 大彩串口屏用。
如何在 ggplot2 中删除网格线(附示例)
[machinetranslation] - Calculation of Bleu value
MySQL must master 4 languages!
Redis6.0 new feature - ACL (permission control list) implements the restriction of user executable commands and keys
【flask入门系列】flask处理请求和处理响应
Cow sequencing problem