Comment Re:It's far more simple - nature of the network (Score 1) 574
I really do not get your point and suspect you are merely looking for an argument.
You are the one who hasn't made any constructive suggestions on how to solve the problem.
The polling interval or other way of checking if the connection is still alive
First of all, keepalive checks is not the goal. It is merely a means to workaround obstacles getting in the way of solving the real problem. The goal is to get a notification to the phone, when it needs attention. The deadline to get the notification there is on the order of five seconds, possibly less. At the same time there is no power budget to send packets every five seconds, even sending a packet every minute may be too power consuming.
How do you propose solving that problem? It is quite clear that it can only be achieve by having the phone passively listening for traffic.
should obviously depend on what the application needs instead of some arbitrary number imposed from elsewhere.
And which polling interval do you suggest using if the needs are: 1: Application must get notified no later than five seconds after a certain event happening in the cloud. 2: While the application is idle, the radio transmitter on the phone must not be activated more frequently than once every five minutes, to preserve battery power.
If you choose to use polling to solve that problem, you must choose an interval which is shorter than five seconds and longer than five minutes. That is impossible. Opening a TCP connection and waiting for a reply will however work.
Open connections without a way to check if the other end is still there are a bad idea on networks that frequently drop out.
That is not a problem. If the network connection disappears temporarily, then notifications cannot be received while the connection is gone. Users can understand, that they cannot receive notifications while the connection is gone, and that no protocol changes can make that happen. Once the network connection has been re-established, there are two possibilities. Either the device still has the same IP address, in which case the TCP connection is still open. Or the device got a new IP address, in which case the application can get notified about the IP change and take necessary actions to establish a new connection.
The only problem left to consider in case of temporary loss of network connection is the following: The phone may lose network connection temporarily and not realize this, while the connection is gone the server decides the TCP connection needs to be closed and sends a FIN. Due to the FIN getting lost, the FIN gets retransmitted a few times. Eventually the server gives up discards state and stops sending further FIN packets.
This is the situation TCP keepalive is mainly designed to deal with. Additionally there is the possibility that the server crashed and got rebooted and thereby lost all TCP connections without having a chance to send a FIN. Use TCP keepalive to ensure both of those situations are noticed by the application. If you just use keepalives for this, you don't need frequent keepalives, because this is not in the critical path for receiving notifications about events in the cloud.