Mqtt精髓系列之心跳机制

翻译:https://www.hivemq.com/blog/mqtt-essentials-part-10-alive-client-take-over

心跳机制

  Keep Alive指定连接最大空闲时间T,当客户端检测到连接空闲时间超过T时,必须向Broker发送心跳报文PINGREQ,Broker收到心跳请求后返回心跳响应PINGRESP。若Broker超过1.5T时间没收到心跳请求则断开连接,并且投递遗嘱消息到订阅方;同样,若客户端超过一定时间仍没收到心跳响应PINGRESP则断开连接。
  连接空闲时发送心跳报文可以降低网络请求,弱化对带宽的依赖。

Keep Alive设定时机

  创建连接时,在CONNECT报文中指定,单位s。

Client Take-Over

场景:客户端与Broker连接正常,然后客户端快速重启(小于1.5T),再重新连接Broker,在未达到1.5T这段时间内,客户端与Broker存在两条连接。
处理措施: 先断开之前的连接再建立新的连接。

A disconnected client will most likely try to connect again. It could be the case that the broker still has an half-open connection for the same client. In this scenario the MQTT will perform a so-called client take-over. The broker will close the previous connection to the same client (determined by the same client identifier) and establishes the connection with the newly connected client. This behavior makes sure that half-open connection won’t stand in the way of a new connection establishment of the same client.

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值