Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mosquitto-dev] mosquitto disconnect callback questions

Hi Steve,

> Let's assume I've started an async connection, set a disconnect callback, then
> call mosquitto_loop_start().

> If the Mosquitto broker unexpectedly disconnects me it appears from the
> documentation for mosquitto_reconnect_delay_set that if I did nothing the client
> tries to reconnect, is that correct?

That is correct, if you use mosquitto_loop_start() the behaviour is to
always reconnect on an unexpected disconnect.

> Once that reconnection happens do I lose any subscriptions I had and have to
> resubscribe, or do they stick to the new connection?

This depends on the type of connection you originally made to the
server. If you call connect with clean_session=true, then when you
disconnect or reconnect, all of the session information on the server
is removed. If you use clean_session=false, then the session
information is kept, including the subscriptions you made.

If you want to have clean_session=true, then the way to handle
subscriptions is to put them in your on_connect() callback - they will
be remade whenever the connection drops unexpectedly.

> If I set a disconnect callback does the automatic reconnection still happen?


> If I get the disconnection callback and want my code to exit, do I still have to
> call mosquitto_disconnect() before calling mosquitto_loop_stop()?


> If I do get automatically reconnected and my subscriptions are restored it
> appears maybe most clients wouldn't actually have any reason to install a
> disconnect callback.

If you're using mosquitto_loop_start(), then I'd agree that using a
disconnect callback isn't that useful.



Back to the top