This is the link to my code. On service start a socket a created that sends data to the server from android client. This service is stopped on destroy.
But I noticed, if my client loses connection with the server I have no way of knowing it and worse I cannot reconnect to the server.
I assume the best way would be to receive an echo of the command sent by the client to the server and if there is no reply from server understand that the connection is lost. After knowing that the connection is lost I need to self stop the service and restart it. I have no idea how to go about it. After doing this I need to rebind to the activity.
The other way is the client socket should be opened and closed for every data being sent. This way it automatically reconnects to the server. I do not know how to do this too.
Any help is appreciated