Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

java.net.SocketTimeoutException: Read timed out

843790Feb 19 2009 — edited Feb 23 2009
Hi,

i use the following code to read several http pages from several sites. it works in most cases but I have problems for 1 site. for this particular site I downbload then pages. for one or more pages (not always the same) I quite often get a java.net.SocketTimeoutException: Read timed out error.
This happens regardless the timeout I set, in fact it seems the timeout has no effect att all.

I use jdk1.6.0_11

the code:

try
{
PrintWriter fileout = new PrintWriter( new BufferedWriter( new FileWriter( new File( filename ))));
URL sourceURL = new URL( url );
String str = "";
URLConnection uc = sourceURL.openConnection();
uc.setConnectTimeout(120000);
uc.setReadTimeout( 120000 );
BufferedReader in = new BufferedReader( new InputStreamReader( uc.getInputStream() ) );

while(!(null==(str=in.readLine()) ) )
{
fileout.println(str);
}//while
in.close();
fileout.close();

}
catch(MalformedURLException e)
{
err=1;
System.out.println("fetch html page (err1):" url" "+e.toString());
}
catch(IOException e)
{
err=2;
System.out.println("fetch html page (err2):" url" "+e.toString());
System.out.println( extractStackTrace(e) );
}
return err;


the error I get:

java.net.SocketTimeoutException: Read timed out
SocketInputStream.java-2java.net.SocketInputStreamjava.net.SocketInputStream.socketRead0(Native Method)
SocketInputStream.java129java.net.SocketInputStreamjava.net.SocketInputStream.read(SocketInputStream.java:129)
BufferedInputStream.java218java.io.BufferedInputStreamjava.io.BufferedInputStream.fill(BufferedInputStream.java:218)
BufferedInputStream.java258java.io.BufferedInputStreamjava.io.BufferedInputStream.read1(BufferedInputStream.java:258)
BufferedInputStream.java317java.io.BufferedInputStreamjava.io.BufferedInputStream.read(BufferedInputStream.java:317)
HttpClient.java687sun.net.www.http.HttpClientsun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
HttpClient.java632sun.net.www.http.HttpClientsun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
HttpURLConnection.java1049sun.net.www.protocol.http.HttpURLConnectionsun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049)


Any ideas where my error is? not, I can at any time open these pages in e.g. firefox.

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 23 2009
Added on Feb 19 2009
7 comments
2,158 views