Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto reconnect #51

Open
mathankumar-dotworld opened this issue May 28, 2024 · 3 comments
Open

Auto reconnect #51

mathankumar-dotworld opened this issue May 28, 2024 · 3 comments

Comments

@mathankumar-dotworld
Copy link

Hi,

The MQTT client works well, but I need to implement auto-reconnect for internet reconnections, server disconnections, and similar issues.

@davidepianca98
Copy link
Owner

Hello, auto-reconnect is something I want to implement but I am not sure when I will be able to do it. In the meantime it's possible to obtain a similar behaviour by creating a new client object every time.

@qwerty470
Copy link

qwerty470 commented Jan 5, 2025

@davidepianca98 Will creating a new publisher client object with the same client ID for each connection cause the broker to discard queued messages from the previous connection for that client? If so, then that's the issue as subscriber client might miss the undelivered messages.
MQTTV5

@davidepianca98
Copy link
Owner

@qwerty470 it should not if clean start is set to false. From the MQTT specification:

3.1.2.4 Clean Start

Position: bit 1 of the Connect Flags byte.

This bit specifies whether the Connection starts a new Session or is a continuation of an existing Session. Refer to section 4.1 for a definition of the Session State.

If a CONNECT packet is received with Clean Start is set to 1, the Client and Server MUST discard any existing Session and start a new Session [MQTT-3.1.2-4]. Consequently, the Session Present flag in CONNACK is always set to 0 if Clean Start is set to 1.

If a CONNECT packet is received with Clean Start set to 0 and there is a Session associated with the Client Identifier, the Server MUST resume communications with the Client based on state from the existing Session [MQTT-3.1.2-5]. If a CONNECT packet is received with Clean Start set to 0 and there is no Session associated with the Client Identifier, the Server MUST create a new Session [MQTT-3.1.2-6].

The not yet acknowledged packets are part of the session. So if cleans start is set to true, they will be discarded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants