Keep alive for MQTT vs TCP

#1

I am trying to reduce the data consumed by the device which is connected to my private MQTT server with a keep alive value of 300secs.

I am analyzing the packets from the device to server with wireshark and I see MQTT ping requests every 300 seconds but I also see TCP keep alive packets at 60 sec intervals.

Is this the expected behavior or should the TCP keep alive and MQTT keep alive needs to be same? Is it possible to change the keep alive interval for TCP?

1 Like
#2

TCP keep-alive and MQTT or Websocket pings are completely independent. The main reason for the top-level pings is to survive proxies.
It is possible to change everything - my understanding is that you’d like to get rid of pings or make them rare?

#3

I would like to make tcp keep-alive packets rare. Where can I make this change?

#4

setsockopt SO_KEEPALIVE and friends on a MQTT socket.
If you’re using Mongoose library, struct mg_connection *c; .... c->sock is the socket in question.

#5

where can I find definition for setsockopt function?