I have a server program in python which sends and receives data packets to and from android client. I am using TCP with sockets in android client to communicate with python program. 
Every thing is working fine but when the server is shutdown with an NSF power failure it disconnected from client. 
My Question is how I check for the availability of the server all the time using android services or any BroadcastReceiver or inside my MainActivity when socket closed or disconnected. 
I don't want to restart my client application again after server power failure.
You can send ping packets to check if the server is alive.
How to reconnect with socket after server power failure from Android Client