I’m using HL6528RD modem to implement an MQTT client over a TCP socket.
The TCP socket status is polled every 100ms to check if any data is available to read.
The TCP socket is open at application startup and keeps opened until I decide to close the MQTT connection.
I noticed that every 150 sec (more or less), the +KTCPSTAT command returns 5 as , i.e. “Socket is closed”. In such a situation, I close the socket and reopen it as suggested in this thread: “TCP session with HL6528”.
My question is: why the socket gets closed every 150 sec (if I don’t have any activity on it)? Is it some TCP timeout related to the network operator? Is there any way to control/avoid it?
Hi sabinocolonna,
TCP timeout is configured by TCP server ( if there is not any activity, after this timeout server will close the session). If you manage this server, you can change this value. If not, please add code in your application to send something to server before that timeout. This value is not related to network or module.
Thanks,
Could you suggest a different setting to avoid socket shutdown on client side? I already have a 30 secs keepalive mechanism at application layer: reducing it at 2 mins solves the problem but I’d like to keep it as long as possible and bypass TCP keepalive.
Thanks for the reply. It was the same doubt I had. But here are other questions:
May it be that TCP timeout settings are different on the intermediate network equipment and these may impact on the socket shutdown?
If the server implements a TCP keepalive strategy, why the TCP stack inside the HL6528RD modem does not respond to the probing packets coming from the server?
Yes, the network equipment can kill the idle TCP socket, such as firewall, so these devices may impact on the socket shutdown.
And HL6 series do not provide any AT interface to config keepalive. Please enable KTCP_ACK in KTCPCFG command to check if any URC is returned or not.
AT+KTCPCFG= [], , [], <tcp_port>[, [<source_port>]
[<data_mode>],
[]], [<SSL profile]
with URC-ENDTCP-enable = 1