Keep alive message

In MQTT architecture, clients and brokers connect to each other and send messages to and fro. There is a chance that one of the clients will get disconnected due to an unforeseen issue, such as an unreliable network or a power outage. Such a state is called a half-open connection, where the broker is not aware of the client's unavailability and is trying to send a message and waiting for acknowledgment.

To overcome this issue, MQTT provides the keep alive functionality, which assures us that the connection between client and the broker is still alive. The MQTT connect message has the provision of the keep alive flag and its value (in seconds) can be set when connecting for the first time to the broker. The keep alive time is the maximum timeout between message exchanges. If the broker does not receive a message from the client for a time period of more than 150% of the keep alive time, it is considered a half-open connection and the broker will disconnect itself from the client and become free, which saves lots of resources.

So if a client needs to maintain a connection with the broker even if there are no messages to transfer, it must send a PINGREQ message within a keep alive interval, and the broker responds back with a PINGRESP message.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.118.198