0

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.

MohK
  • 1,873
  • 1
  • 18
  • 29
  • On line 311 there are gremlins dancing. You can prove me wrong with a [mcve]. – user4581301 Jul 02 '18 at 06:27
  • You can't have UDP keep-alive time to 10 mins. NAT mapping may disappear by that time. In my opinion anything more than 30 sec is risky. See - https://stackoverflow.com/questions/30354131/for-how-long-a-router-keeps-records-in-the-nat-and-can-they-be-reused-forwarding – taskinoor Jul 02 '18 at 06:38
  • @taskinoor, so I guess I need to use TCP instead UDP ? But it may not possible. – MohK Jul 02 '18 at 07:38
  • 1
    TCP and UDP has different use cases. I can't tell whether TCP would serve your purpose. – taskinoor Jul 02 '18 at 07:59

0 Answers0