I am using UDP sockets through C++ code and using NDK. I have a constant ping-pong(keep-alive) mechanism to keep connection active in my protocol.
I have one thread which is constantly looking for incoming messages from server which is running infinitely.
while(true){
..... some code
int llen = recvfrom(fd, buf, BUFLEN, 0, (const sockaddr *)&si_other, (socklen_t*)&slen);
..... some code
}
Communication works good if I keep ping-pong time to nearly 30 seconds even if device is idle.
But if I put ping-pong time to 10 minutes, and if server sends some data at 7th minute. It not reaches to client (android device) even if ip/port of the device is same in idle state.
Notes :
- I have to keep ping-pong at 10 minutes.
- I am using Partial wake lock.
- I cannot use push notifications through firebase.
- Doze is not affecting as my app is whitelisted.
- I am also using AlarmManager to send ping-pong.
What can be the solution to the problem I am facing? Any idea will be good.