Thales' cellular IoT products business is now part of Telit Cinterion, find out more.

You are here

SocketConnection KEEPALIVE socket option does not work | Telit Cinterion IoT Developer Community

November 30, 2015 - 8:52pm, 8214 views

Hi,

I've written a client socket connection to a TCP server. I want this connection to be open a long time so that the server can send me asynchronous events, as they are generated on the server side.

On the cellular network I operate, TCP connections are flushed from the NAT tables after 30 minutes of inactivity.

So, to prevent TCP connections from dropping after 30 minutes, I decided to use the keepalive socket option. The option doesn't allow you to specify the 3 options described in the TCP KEEPALIVE documentation (tcp_keepalive_time, tcp_keepalive_intvl, tcp_keepalive_probes). It only allows you to enable it or not, which is rather limited in my opinion - anyways.

So I enabled KEEPALIVE on my client SocketConnection instance by doing this, immediately after Connector.Open returned the instance:

  socConn.setSocketOption(SocketConnection.KEEPALIVE, 1);
  if(socConn.getSocketOption(SocketConnection.KEEPALIVE) == 0) {
    // error handling: Close socket and return error.
  }

But lo and behold, after 1 hour of waiting for a keepalive packet, I did not get any. I used tcpdump to verify this. Needless to say, by that time my TCP connection entry in had timed out in my operator NAT table and the connection was in limbo.

Inversely, I coded my  own TCP server and implemented the KEEPALIVE TCP socket options (in C, linux) and tested with this. Keepalives were seen and kept my connection up for two hours.

Anyone else has issues with TCP KEEPALIVE using the SocketConnection?
I'm using the IMP-NG EHS5 Wireless Toolkit (cwnlib_1.0).

Thanks!