0

I'm using Paho to communicate with an MQTT broker and all the example I found (like this) do these 3 steps when performing an action (publish or subscribe):

  1. connect to the broker
  2. do action
  3. disconnect

My question is: are there any drawbacks holding a connection for the whole life of the application instead of opening/closing it for each action? Isn't it a faster solution removing the time for opening the connection?

1 Answer 1

2

No, holding a connection open for the lifetime of the application is a fully expected usecase, it's the only real way you'd be able to subscribe to a topic and receive messages when they are published.

The protocol has built in ping messages to ensure the broker knows the client is still connected.

The examples tend to be relatively trivial but want to show the full life cycle of the client which is why they connect, do something, disconnect

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.