Closed cyjaysong closed 6 months ago
Looks like you've disconnected somehow, hence the client is now closed, without any more context of what you are doing that's all I can say really.
Yes, due to network fluctuations, the connection has been disconnected and it is automatically reconnecting
OK but you seem to be calling disconnect(), if you want to use the autoreconnect functionality you must set the auto reconnect flag and not call disconnect yourself, I'll need a full log to go any further.
Yes, I called discount when the user account was logged out, and I think that after actively calling discount, there will be no automatic reconnection
If you call disconnect() you must call connect() again before using the client.
I think it executed reconnect after I called disconnect
The client doesn't do this automatically, you have to call connect if you have called disconnect. I've done a quick update to the mqtt_server_client example to reconnect when the disconnect callback is triggered, output -
EXAMPLE::Mqtt5 client connecting....
EXAMPLE::OnConnected client callback - Client connection was successful
EXAMPLE::Mqtt5 server client connected, return code is success
EXAMPLE::Subscribing to the test/lol topic
EXAMPLE::Subscribing to the Dart/Mqtt5_client/testtopic topic
EXAMPLE::Sleeping....
EXAMPLE::Subscription confirmed for topic test/lol
EXAMPLE::Subscription confirmed for topic Dart/Mqtt5_client/testtopic
EXAMPLE::Publishing our topic now we are subscribed
EXAMPLE::Published notification:: topic is Dart/Mqtt5_client/testtopic, with Qos MqttQos.exactlyOnce
EXAMPLE::Change notification:: topic is <Dart/Mqtt5_client/testtopic>, payload is <-- Hello from mqtt5_client -->
EXAMPLE::Unsubscribing
EXAMPLE::Disconnecting
EXAMPLE::OnDisconnected client callback - Client disconnection
EXAMPLE::OnDisconnected callback is solicited, topic has been notified - this is correct
>>>>> Attempting reconnect >>>>
EXAMPLE::OnConnected client callback - Client connection was successful
You can see that we reconnect successfully when disconnect has been called. You seem not to be doing this, you sem to be destroying the client somehow.
StateError:Bad state: Cannot add new events after calling close File "broadcast_stream_controller.dart", line 243, in _BroadcastStreamController.add File "event_bus.dart", line 61, in EventBus.fire File "mqtt_connection_handler_base.dart", line 162, in MqttConnectionHandlerBase.autoReconnect