AfterDisconnect is not triggering after network disconnect

Hi!

i have made a Client with the hivemq-mqtt-client-dotnet library in c#.

The initial connect works fine, and OnMessageReceived event get triggered on incomming messages.

The problem is that when the connection failes, the client never notices.
if i unplug my ethernet-cable, the client.AfterDisconnect never triggers.
client.IsConnected() - flag also stays true.

So for now i have no working reconnect since i’m not able to detect when connection failes.

is there any way to detect when connection to the broker is missing?

Hi @Tverfyll

Greetings! We’re thrilled to have you here, showing interest in MQTT and the HiveMQ broker. Welcome to the HiveMQ Community! We’re always happy to see new users.

You mentioned that you made a client using the hivemq-mqtt-client-dotnet library in C#. However, you didn’t provide a link to the project. Was that an oversight?

Thanks,
Dasha from the HiveMQ Team

Hi @Daria_H

i have now uploaded the relevant code to github/Tverfyll/HiveMQ. Hope this helps.

Hello @Tverfyll ,

With some additional review of the C# client library, we do have an example available within our GitHub, here, that provides example reconnect strategies on the event of a disconnect.

It is worth mentioning that in this example, the handler client.AfterDisconnect is utilized for reconnect strategies, as this is called on a client disconnect.

Let us know if this answers your question, or if there is additional assistance we can provide!

Best,
Aaron from the HiveMQ Team

Hi @AaronTLFranz,

i have seen the reconnect example, but my code never gets there.

My issue is that the handler client.AfterDisconnect only triggers in cases with normal disconnect, either from the client or the broker.

In cases where the server looses internet connection, the C# Client library think it’s still connected.
Even the client.IsConnected() returns true with the ethernet cable disconnected.

Is there a connection watchdog or something that i’m missing?

Tverfyll