This bit specifies the handling of the Session state.
The Client and Server can store Session state to enable reliable messaging to continue across a sequence
of Network Connections. This bit is used to control the lifetime of the Session state.
If CleanSession is set to 0, the Server MUST resume communications with the Client based on state from
the current Session (as identified by the Client identifier).
If there is no Session associated with the Client identifier the Server MUST create a new Session.
The Client and Server MUST store the Session after the Client and Server are disconnected.
After the disconnection of a Session that had CleanSession set to 0, the Server MUST store
further QoS 1 and QoS 2 messages that match any subscriptions that the client had at the time of disconnection
as part of the Session state.
It MAY also store QoS 0 messages that meet the same criteria.
If CleanSession is set to 1, the Client and Server MUST discard any previous Session and start a new one.
This Session lasts as long as the Network Connection. State data associated with this Session MUST NOT be reused
in any subsequent Session.
The Session state in the Client consists of:
QoS 1 and QoS 2 messages which have been sent to the Server, but have not been completely acknowledged.
QoS 2 messages which have been received from the Server, but have not been completely acknowledged.
To ensure consistent state in the event of a failure, the Client should repeat its attempts to connect with
CleanSession set to 1, until it connects successfully.
Typically, a Client will always connect using CleanSession set to 0 or CleanSession set to 1 and not swap
between the two values. The choice will depend on the application. A Client using CleanSession set to 1 will
not receive old Application Messages and has to subscribe afresh to any topics that it is interested in each
time it connects. A Client using CleanSession set to 0 will receive all QoS 1 or QoS 2 messages that were
published while it was disconnected. Hence, to ensure that you do not lose messages while disconnected,
use QoS 1 or QoS 2 with CleanSession set to 0.
When a Client connects with CleanSession set to 0, it is requesting that the Server maintain its MQTT session
state after it disconnects. Clients should only connect with CleanSession set to 0, if they intend to reconnect
to the Server at some later point in time. When a Client has determined that it has no further use for
the session it should do a final connect with CleanSession set to 1 and then disconnect.
This bit specifies the handling of the Session state. The Client and Server can store Session state to enable reliable messaging to continue across a sequence of Network Connections. This bit is used to control the lifetime of the Session state.
If CleanSession is set to 0, the Server MUST resume communications with the Client based on state from the current Session (as identified by the Client identifier). If there is no Session associated with the Client identifier the Server MUST create a new Session. The Client and Server MUST store the Session after the Client and Server are disconnected. After the disconnection of a Session that had CleanSession set to 0, the Server MUST store further QoS 1 and QoS 2 messages that match any subscriptions that the client had at the time of disconnection as part of the Session state. It MAY also store QoS 0 messages that meet the same criteria.
If CleanSession is set to 1, the Client and Server MUST discard any previous Session and start a new one. This Session lasts as long as the Network Connection. State data associated with this Session MUST NOT be reused in any subsequent Session.
The Session state in the Client consists of: QoS 1 and QoS 2 messages which have been sent to the Server, but have not been completely acknowledged. QoS 2 messages which have been received from the Server, but have not been completely acknowledged.
To ensure consistent state in the event of a failure, the Client should repeat its attempts to connect with CleanSession set to 1, until it connects successfully.
Typically, a Client will always connect using CleanSession set to 0 or CleanSession set to 1 and not swap between the two values. The choice will depend on the application. A Client using CleanSession set to 1 will not receive old Application Messages and has to subscribe afresh to any topics that it is interested in each time it connects. A Client using CleanSession set to 0 will receive all QoS 1 or QoS 2 messages that were published while it was disconnected. Hence, to ensure that you do not lose messages while disconnected, use QoS 1 or QoS 2 with CleanSession set to 0.
When a Client connects with CleanSession set to 0, it is requesting that the Server maintain its MQTT session state after it disconnects. Clients should only connect with CleanSession set to 0, if they intend to reconnect to the Server at some later point in time. When a Client has determined that it has no further use for the session it should do a final connect with CleanSession set to 1 and then disconnect.