Hi All !!!
I am trying to create a program to connect to some server wherein, I intend to implement time out. However I have observed that this feature is supported by Java5.0 API, but sadly its missing in Java 1.4.x, which happens to be my production environment.
If any of you guys could direct me to a hint, it would be very helpful.
My Sample Code follows -
Thanks in advance,
SwapSawe.
Cheer Up, The worst is yet to Come.
I am trying to create a program to connect to some server wherein, I intend to implement time out. However I have observed that this feature is supported by Java5.0 API, but sadly its missing in Java 1.4.x, which happens to be my production environment.
If any of you guys could direct me to a hint, it would be very helpful.
My Sample Code follows -
Code:
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class CheckHTTPURLConnection {
public static void main(String args[]) {
long t0=0;
try {
URL u = new URL("[URL unfurl="true"]http://kbs.cs.tu-berlin.de/~jutta/ht/responses.html");[/URL]
HttpURLConnection huc = (HttpURLConnection) u.openConnection();
huc.setRequestMethod("TRACE");
huc.setDoInput(true);
huc.setDoOutput(true);
/* Does not work
huc.setConnectTimeout(3000);
*/
t0= System.currentTimeMillis();
huc.connect();
OutputStream os = huc.getOutputStream();
int code = huc.getResponseCode();
System.out.println("The Returned code is :"+code);
if (code == 200 ) {
System.out.println("Got the connection");
}
huc.disconnect();
}
catch(java.net.SocketTimeoutException ste) {
/* Would never be thrown as setConnectTimeout not supported in Java 1.4.x
System.out.println("Time Limit Exceeded.");
}
catch (IOException e) {
System.out.println("Connection Failed : Why? A:"+e);
}
long t1= System.currentTimeMillis();
System.out.println("Total time taken :"+(t1-t0));
}
}
Thanks in advance,
SwapSawe.
Cheer Up, The worst is yet to Come.