MQTT IsConnected property

Hello. Property IsConnected in Mqtt never set to false. When I turn off my MQTT server but, property IsConnected = true;

Try to wait about few second. It will set to false when try to ping and failed. Isn’t it?

not working…

  1. Run MQTT server
  2. When IsConnected == true, i send packet “client.publish(…) every one second”
  3. Shutdown MQTT server after 5 minutes
  4. IsConnected == true and call function “Send” in library MQTT. In every call “Send” value lastCommunationInMilisecond set to current time (lastCommunationInMilisecond = ToMillisecond(DateTime.Now.Ticks);).
  5. IsConnected never set to false, because function “PingReq” in library MQTT never call.
    var d = ToMillisecond(DateTime.Now.Ticks) - this.lastCommunationInMilisecond;

It will be called depends on KeepAliveTimeout value. Default is 60 seconds.
Below is we tried at 20 seconds.

var connectSetting = new MqttConnectionSetting
                {
                    ClientId = DeviceId,
                    UserName = Username,
                    Password = Password,
                    KeepAliveTimeout = 20,
                };

var d = ToMillisecond(DateTime.Now.Ticks) - this.lastCommunationInMilisecond;
d = 980
keepAliveTimeoutInMilisecond = 20000

value this.lastCommunationInMilisecond always update to ToMillisecond(DateTime.Now.Ticks) after call Publish("…");
I call the Publish ("…") function every second, because IsConnected = true

“d” is always less than “this.lastCommunationInMilisecond” and “PingReq” never called.