tags:

views:

32

answers:

2

friends,

I'm running into an issue when i try to call webservice and the server/internet is not available. It appears that the connection is taking a long time to timeout

can i set timout manually to show error messgage to user?

any help would be appreciated.

A: 

You can try to do it this way:

URL url;
URLConnection connection;
try {
    url = new URL("http://foo.bar.com");
    connection = url.openConnection();
    connection.setConnectTimeout(3000); // set 3 seconds for timeout
    connection.connect();
}catch(SocketTimeoutException ss){
    // show message to the user
}
Cristian
+1  A: 

Set up your HttpClient this way.

    BasicHttpParams httpParams = new BasicHttpParams();
    ConnManagerParams.setTimeout(httpParams, connectionTimeoutInMs);
    httpClient = new DefaultHttpClient(httpParams);
BrennaSoft
This worked for me, but it did not throw an exception, furthermore, the status parsed with a 200 OK.
mobibob