I implemented a REST client using HttpURLConnection
. The problem is when I do a particular actions on the server, the server may temporally goes out of the network and comes back in a while. But the client expects response and it waits at conn.getInputStream()
till the time out. The thread waits even after the server came to network back.
Is there any way I can understand when a server goes out of reach while a connection is enabled?
Sample code:
PrintWriter out = new PrintWriter(conn.getOutputStream(), true);
out.println(data);
....
response.append(convertInputStreamContentToString(conn.getInputStream()));
.....