Closed zhuewizz closed 4 years ago
This is because the example disconnects here : I/flutter (16938): EXAMPLE::Disconnecting
what you are supposed to do is restart the broker when prompted to do so, as in this line
EXAMPLE::Ping response client callback invoked - you may want to disconnect your broker here
I'll see if I can stop this however.
annotating the code, run ok
/* /// Ok, we will now sleep a while, in this gap you will see ping request/response /// messages being exchanged by the keep alive mechanism. print('EXAMPLE::Sleeping....'); await MqttUtilities.asyncSleep(120);
/// Finally, unsubscribe and exit gracefully
print('EXAMPLE::Unsubscribing');
client.unsubscribe(topic);
/// Wait for the unsubscribe message from the broker if you wish.
await MqttUtilities.asyncSleep(2);
print('EXAMPLE::Disconnecting');
client.disconnect();
*/
1、There is an open reconnection
client.autoReconnect = true; client.onAutoReconnect = onAutoReconnect;
2、Run for a period of time to report an exception
I/flutter (16938): 2020-05-22 18:47:27.983554 -- MqttConnection::_onData I/flutter (16938): 2020-05-22 18:47:27.990922 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.unsubscribeAck I/flutter (16938): Header: MessageType = MqttMessageType.unsubscribeAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2 I/flutter (16938): UnsubscribeAck Variable Header: MessageIdentifier={4} I/flutter (16938): 2020-05-22 18:47:27.991908 -- MqttServerConnection::_onData - message processed I/flutter (16938): EXAMPLE::Disconnecting I/flutter (16938): 2020-05-22 18:47:29.980322 -- SynchronousMqttServerConnectionHandler::disconnect I/flutter (16938): 2020-05-22 18:47:29.984061 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.disconnect I/flutter (16938): Header: MessageType = MqttMessageType.disconnect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0 I/flutter (16938): mian end... I/flutter (16938): 2020-05-22 18:47:30.043648 -- MqttConnectionBase::_onDone - calling disconnected callback E/flutter (16938): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The getter 'autoReconnectInProgress' was called on null. E/flutter (16938): Receiver: null E/flutter (16938): Tried calling: autoReconnectInProgress E/flutter (16938): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5) E/flutter (16938): #1 MqttClient.internalDisconnect (package:mqtt_client/src/mqtt_client.dart:327:30) E/flutter (16938): #2 MqttConnectionBase.onDone (package:mqtt_client/src/connectionhandling/mqtt_client_mqtt_connection_base.dart:65:21) E/flutter (16938): #3 _rootRun (dart:async/zone.dart:1180:38) E/flutter (16938): #4 _CustomZone.run (dart:async/zone.dart:1077:19) E/flutter (16938): #5 _CustomZone.runGuarded (dart:async/zone.dart:979:7) E/flutter (16938): #6 _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:392:13) E/flutter (16938): #7 _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:402:15) E/flutter (16938): #8 _BufferingStreamSubscription._close (dart:async/stream_impl.dart:286:7) E/flutter (16938): #9 _SyncStreamControllerDispatch._sendDone (dart:async/stream_controller.dart:787:19) E/flutter (16938): #10 _StreamController._closeUnchecked (dart:async/stream_controller.dart:644:7) E/flutter (16938): #11 _StreamController.close (dart:async/stream_controller.dart:637:5) E/flutter (16938): #12 _Socket._onData (dart:io-patch/socket_patch.dart:1989:21) E/flutter (16938): #13 _rootRunUnary (dart:async/zone.dart:1196:13) E/flutter (16938): #14 _CustomZone.runUnary (dart:async/zone.dart:1085:19) E/flutter (16938): #15 _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7) E/flutter (16938): #16 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11) E/flutter (16938): #17 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:266:7) E/flutter (16938): #18 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:779:19) E/flutter (16938): #19 _StreamController._add (dart:async/stream_controller.dart:655:7) E/flutter (16938): #20 _StreamController.add (dart:async/stream_controller.dart:597:5) E/flutter (16938): #21 new _RawSocket. (dart:io-patch/socket_patch.dart:1534:35)
E/flutter (16938): #22 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1012:18)
E/flutter (16938): #23 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
E/flutter (16938): #24 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
E/flutter (16938):