stevenlovegrove / MqttDotNet

.net Implementation of the client half of the MQTT messaging protocol. MQTT is a lightweight, open specification publish and subscribe protocol cheifly developed by IBM. Details of MQTT can be found at http://mqtt.org.
MIT License
153 stars 91 forks source link

Too frequent PINGREQ #7

Closed CapnBry closed 11 years ago

CapnBry commented 11 years ago

Doing some network debugging I found that all of my mqtt clients were pinging the server every 10 seconds. The library uses 1/3rd the keepalive interval as the timeout? https://github.com/stevenlovegrove/MqttDotNet/blob/master/MqttLib/Mqtt.cs#L169

That seems arbitrary and the spec already states that the keepalive is the expected interval, with a 50% grace period in addition to the keepalive time. As such, I think the keepalive time specified should be the ping interval rather than 3x the ping interval. The client also should also reset the timer when it publishes a message.

int kmillis = _keepAlive * 1000;
keepAliveTimer.Change(kmillis , kmillis);

This change is mainly for reducing power usage on battery powered platforms where transmits are somewhat expensive.

Reference: http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html#keep-alive-timer

stevenlovegrove commented 11 years ago

Thanks for the info. It sounds like you've made these changes already - would you like to test that it works and then raise a pull request?

CapnBry commented 11 years ago

Yup can do. I've been testing it a few days already. I'll put up a pull request tomorrow. Thanks for the great library!