I am currently writing a program that requires a client-server communication, the server is a machine in an office and the clients will be Android devices. The clients will connect to the server and wait for data to be sent to them. The clients will be running for hours at a time and a constant connection is required. From research I have found that an open connection will not keep the radio at full power so I'm happy to keep this connection open. All this I have done and works fine. My issue is when the server is switched off / lost network connection etc. The Android clients do not know when the connection has been closed.
In my research I have found that the Java Socket API does not know when a connection has been closed /lost connection by the server (see Java socket API: How to tell if a connection has been closed?) for info. As suggested in some of the replies (and other sources I have seen), it is advised to use a heartbeat to "test" the connection. This poses an issue with Android as the heartbeat method may result in extra battery useage with is obviously something to avoid.
Before I started to write any code I researched Google Cloud Messaging but due to the requirements for the software I am writing, Cloud Messaging is not appropriate (due to Throttling).
Due to the requirements of the software and the eventual users of the app I know that most of the time the Android devices will be connected to a power source so the battery drain issue could be considered mute! However I would rather keep to best practices in regards to battery conservation.
In this regard, does anyone know of a way to tell if the connection is still open, other than the heartbeat approach of course?
Cheers guys.