shamblett / mqtt_client

A server and browser based MQTT client for dart
Other
552 stars 179 forks source link

AutoReconnect does not work #206

Closed pranjal-joshi closed 4 years ago

pranjal-joshi commented 4 years ago

Hello, I am trying to implement an auto-connect to handle network switching or connection drops. However, after implementing an auto-connect, it simply triggers the auto-connect callback function on the Disconnect event but never actually connects back to the server. My Logs are as bellow:

Restarted application in 1,954ms.
I/flutter (17736): [+] SmartMqtt -> MQTT Client connecting...
I/flutter (17736): [+] SmartMqtt -> MQTT Connected!
I/flutter (17736): Hello there!
I/flutter (17736): [+] SmartMqtt -> MQTT Reconnected!
E/flutter (17736): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: SocketException: OS Error: Software caused connection abort, errno = 103, address = MASKED_MY_IP_FROM_HERE, port = 43300
E/flutter (17736):

Code snippet:

    ....
    client = MqttServerClient.withPort(ip, '', port);
    client.logging(on: false);
    client.keepAlivePeriod = 30;
    client.autoReconnect = true;
    client.onAutoReconnect = this.onAutoReconnect;
    client.onConnected = this.onConnected;
    client.onDisconnected = this.onDisconnected;
    client.onSubscribed = this.onSubscribed;
    ....
shamblett commented 4 years ago

OK, I'll need the log from the client itself, i.e turn logging on, note that auto-reconnect will reconnect to your existing connection parameters, what does your 'network switching' mean above?

pranjal-joshi commented 4 years ago

OK, I'll need the log from the client itself, i.e turn logging on, note that auto-reconnect will reconnect to your existing connection parameters, what does your 'network switching' mean above?

Hello, This was happening due to poor network reception quality. And by network switching, I mean switching from WiFi to LTE or vice-versa! Thanks for the great plugin! 👍