MQTT Keep Alive
MQTT includes a keep alive function that provides a workaround for the issue of half-open connections (or at least makes it possible to assess if the connection is still open).
Keep alive ensures that the connection between the broker and client is still open and that the broker and the client are aware of being connected. When the client establishes a connection to the broker, the client communicates a time interval in seconds to the broker. This interval defines the maximum length of time that the broker and client may not communicate with each other.
As long as messages are exchanged frequently and the keep-alive interval is not exceeded, there is no need to send an extra message to establish whether the connection is still open.
If the client does not send a messages during the keep-alive period, it must send a PINGREQ packet to the broker to confirm that it is available and to make sure that the broker is also still available.
The broker must disconnect a client that does not send a a message or a PINGREQ packet in one and a half times the keep alive interval.
在keep-alvie interval * 1.5 时间间隔内,client与broker之间无任何数据报文通讯(message or PINGREQ packet),broker会主动断开客户端的连接。
Reference:
1. Keep Alive and Client Take-Over - MQTT Essentials Part 10