Skip to content

Keep alive ​

The keep-alive interval is how long a client may stay silent. It lets both sides notice a dead connection, which TCP alone can take minutes or hours to report.

How it works ​

  1. In the CONNECT packet the client sets a keep-alive interval in seconds, for example 60.
  2. If the client has nothing else to send within that time, its library sends a small PINGREQ; the broker answers with PINGRESP.
  3. If the broker hears nothing from a client for about 1.5 × the keep-alive interval, it closes the connection and publishes the client's Last Will.
  4. If the client gets no PINGRESP in time, it treats the connection as dead and reconnects.

Any packet resets the timer, so a device that publishes every few seconds hardly ever sends a ping.

ConnectMQ values ​

SettingValue
Maximum keep alive600 seconds (10 minutes)
Keep alive 0 (disabled) or above 600Treated as 600
Detection of a silent clientAbout 1.5 × keep alive
Time to send CONNECT after opening the connection3 seconds

The broker applies the 600-second limit without returning a Server Keep Alive value, so a client that asked for more still believes in its own value. Stay at or below 600.

ClientKeep aliveWhy
Devices and gateways on Ethernet or Wi-Fi60 sDetects an outage within about 90 seconds, negligible traffic
Devices on 4G / LTE / NB-IoT120–300 sFewer wake-ups and less data; carriers may still close idle connections sooner
Back-end services30–60 sFast failover
Battery devices that connect, publish and disconnectAnyThe connection is short-lived anyway

Behind NAT routers and mobile carriers, idle TCP connections are often dropped after a few minutes. If a device reconnects regularly without any error, lower its keep alive.

Keep alive and session minutes ​

A connected client uses session minutes whether it is publishing or only pinging (limits). Devices that report rarely can save minutes by connecting, publishing and disconnecting instead of staying connected.

Fully managed MQTT broker for connected devices.