Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] When to invoke MQTTClient_disconnect() and MQTTClient_destroy() in long running application ?

Hi Ian,

Thanks for quick reply. 
Does the library automatically reconnects to broker if disconnection happens with in library (probably through MQTTClient_disconnect_internal function) or application needs to re-connect using MQTTClient_connect() again ?
What is the best practice to re-connect to the broker from application in case of network issues ? Right now we are checking it with MQTTClient_isConnected() function in application code before publishing every message to broker. If it is not connected, then we are connecting again.  

Thanks,
Durgesh

On Wed, May 22, 2019 at 5:08 PM Ian Craggs <icraggs@xxxxxxxxxxxxxxxxxxxxxxx> wrote:

Hi,

no you do not need to call destroy().   That is only to clean up resources when you don't need a client object at all.  If the client object is the last or only one, then destroy() also cleans up resources for the entire library, which has caused some issues under some circumstances.  It's a plan of mine to separate out this library cleanup code into a separate, explicitly called function to avoid those issues entirely but I have not done that yet.

Definitely don't call destroy() unless you really have finished with the client object.  There is no need to recreate during a long running process, just re-connect.

Ian

On 22/05/2019 07:51, Durgesh Tanuku wrote:
Hi,

Our application using paho c mqtt library (version 1.3.0). Recently we have noticed few issues (mostly crashes in library) when application is reconnecting (disconnection, destroy and then connect) to the broker. We are reconnecting to broker when MQTTClient_isConnected() returns false. As I'm new to paho library, I have below queries designing application code with respect to paho library.
1) If underlying library is disconnected from broker due to any network issue, does the application need to reset the connection by destroying existing mqtt client handle ?
2) Can application code use the handle created at initialisation during entire run time of the process ? Will there be any case where application need to reset the existing connection ?

The device on which our application runs, might switch the interfaces and cause network issues.

Thanks,
Durgesh
 

_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/paho-dev
-- 
Ian Craggs
icraggs@xxxxxxxxxx                 IBM United Kingdom
Eclipse Paho Project Lead & Mosquitto Committer
_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/paho-dev

Back to the top