shamblett / mqtt5_client

A server and browser based MQTT 5 client for dart
Other
49 stars 25 forks source link

OnDisconnect not triggered once connection is established #76

Closed dferrarigrowtech closed 8 months ago

dferrarigrowtech commented 8 months ago

I tried your mqtt5_server_client.dart example. Once the connection in established try to disconnect from the server (e.g. disconnect the ethernet cable of the pc), the onDisconnect event will not be triggered. I also tried to set keepAlive period to 5 seconds, but nothing changed.

shamblett commented 8 months ago

Pulling the cable doesn't always work, if the Drat/flutter runtime doesn't generate a network event for this the client knows nothing about it and can't react to it so it stays connected.

If you use keepalive you have to monitor your pong callbacks, if they stop after say 2 or 3 keepalive periods, in your case say 10 or 15 seconds then you should call disconnect() to disconnect the client.