njh / ruby-mqtt

Pure Ruby gem that implements the MQTT protocol, a lightweight protocol for publish/subscribe messaging.
http://www.rubydoc.info/gems/mqtt
MIT License
541 stars 135 forks source link

Don't keepalive ping if disconnected #82

Closed troygnichols closed 8 years ago

troygnichols commented 8 years ago

I'm not 100% sure this is the correct solution, but it solved a problem for me so I thought I'd at least share it and see if it's useful for you.

The problem I'm trying to solve:

Maybe that really is the correct behavior, I dunno, but I would expect pinging to stop once the client disconnects (I'm a noob at MQTT so not sure).

So my solution is just don't do keepalives if the client is disconnected.

njh commented 8 years ago

Yes, this looks good.

If the application is purposefully disconnecting, then there shouldn't be any ping exceptions.

If the network is unexpectedly interrupted, while subscribed, then there should be an exception.

Thanks!

nick.