|
-
August 9th, 1999, 03:21 PM
#1
How to timeout a URL connection?
Does anyone know how to set timeout for a URL connection?
I wrote a small program to fetch content and date of a URL from remote site. However, it hangs on some URLs (I tried these URLs on netscape, they also hangs). I would like to know whether I can set a timeout period for each connection. If you have a better way than writing specific threads to do this, please let me know.
Thanks in advance.
--Changzhou
P.S. The following is my code. I can always got "[JDT-DEBUG] connection opened", but sometimes "[JDT-DEBUG] got date" does not come out, and the program runs forever.
try {
URL url = new URL((String)sites.elementAt(siteIndex)+page.urlPath);
connection = url.openConnection();
// DEBUG-SECTION-BEGIN, BY Java Developement Template
System.out.println("[JDT-DEBUG]"+"["+id+"] connection opened");
// DEBUG-SECTION-END, BY Java Developement Template
} catch (Exception x) {
log("[ERROR] Openning "+page.urlPath+":"+x);
return DOWNLOADING_ERROR;
}
try {
// test if it is necessary to download from remote site
long date = connection.getDate() ;
// DEBUG-SECTION-BEGIN, BY Java Developement Template
System.out.println("[JDT-DEBUG]"+"["+id+"] got date");
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|