I am using the following options to set TCP keep_alive properties on my socket running on Android connected to server running Linux.
int idleTimeout = 3;
setsockopt(socketDescriptor, SOL_TCP, TCP_KEEPIDLE, &idleTimeout, sizeof(int))
int interval = 3;
setsockopt(socketDescriptor, SOL_TCP, TCP_KEEPINTVL, &interval, sizeof(int))
int unackPacketCount = 5;
setsockopt(socketDescriptor, SOL_TCP, TCP_KEEPCNT, &unackPacketCount, sizeof(int))
The Linux server also has keep alive settings turned on in the same fashion.
Question:
Everything works as expected. But if I leave my Android device connected for like 6 to 7 hours, I get a connection timed out error. This could happen after 10 hours or after 3-4 hours. Its really random.
Is this expected because my client is an app running on Android? (Because, I don't see the issue happen when I ran my client on Linux with the same settings) Couldn't my Android socket stay connected forever without timing out?
Environment:
- Running on Android 10 on a Pixel XL
- My Android phone is always connected to charger during the test
- Its a single router between my Android device and the Linux server.