StatusChanged is not working as expected


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...


Still waiting for any response
I'm sending again the project and 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.