I’m using the HttpURLConnection class to make http requests.
My code looks something like this-
while(true){
try{
connection=(HttpURLConnection)url.openConnection();
connection.setDoOutput(true);
connection.setConnectTimeout(2*1000);
InputStream in=connection.getInputStream();
}
catch(SocketTimeOutException e){}
catch(IOException e){}
}
I do some processing on the data once I retrieve the InputStream object. My problem is that if I let the program run long enough, the call to getInputStream blocks and I never get past that.
Am I missing something? Any pointers or help would be greatly appreciated. Thanks.
Set the read time out for the connection.
Also, close the streams in a finally block once you’re done with them.