StatusChanged is not working as expected

Hello,

I'm sending a project and a video describing the scenario where the problem happens:

As you can see in the attached video i'm running a client project connecting to an external mosquitto broker. When I stops the mosquitto broker my client application fire the statuschanged event but when I drop the network of the virtual machine it doesn't fire the statuschanged event, and keep "connected" by mistake...

Attachments:
Project
https://nuvem.grvmax.com.br/grvupload/f.php?h=2hakm1Yp&d=1
Video
https://nuvem.grvmax.com.br/grvupload/f.php?h=2teGSZZ7&d=1

Still waiting for any response
I'm sending again the project and video
Project

Video

This project ZIP has no uPrincipal.pas, neither uPrincipal.dfm .
It's referenced as in a relative path that wasn't included:
uses Vcl.Forms, uPrincipal in '..\..\..\..\ProjetoBase\Mqtt\uPrincipal.pas' {Form1};

Try this link please

When network is down or the server unexpectedly stops, the client does not receive the proper server disconnection message.

If you want to detect that, you'll have to:

  • Enable keepalive settings
  • Write an OnPacketReceive event, and then save the time when you receive packets of type mtPINGRESP
  • Enable a timer to check if your last ping response is kinda compatible with the KeepAliveInterval you've set up.

For example, if you set KeepAliveInterval = 10, then you could check inside of OnTimer if your last mtResponse has been received more than f.i. 15 seconds ago. Then you'll know whether you're still connected or not.

It also could be done without using KeepAliveSettings and the component's internal timer.
Could make it all by pinging manually from a custom TTimer and checking the last response in the same OnTimer event.