I'm working on an android app. The app is acting as a client. It is sending some data to a server continuously (lets say after every half second). The server is running on my PC. How can I detect from my app that the server has closed so that I can notify the user of this? Below is my code to send data from client to server:
Socket socket = null;
PrintWriter out = null;
try {
socket = new Socket(ip, PORT);
out = new PrintWriter(socket.getOutputStream(), true);
out.println(myMessage);
}
catch (IOException e) {
e.printStackTrace();
}