How To Find Server Unavailable In Android
Im developing an app which has download option Local Server in OnState:- From My Android Emulator,I Download Audio File and Save it in Distination Path(Local Server), Then I Played
Solution 1:
What you need here is to setTimeout.
Below code snipper will help you.
HttpPosthttpPost=newHttpPost(url);
StringEntityse=newStringEntity(envelope,HTTP.UTF_8);
httpPost.setEntity(se);
HttpParamshttpParameters=newBasicHttpParams();
// Set the timeout in milliseconds until a connection is established.inttimeoutConnection=3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data.inttimeoutSocket=3000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClienthttpClient=newDefaultHttpClient(httpParameters);
BasicHttpResponsehttpResponse= (BasicHttpResponse) httpClient.execute(httpPost);
HttpEntityentity= httpResponse.getEntity();
return entity;
Here if you dont get response within specific time limit.
Code will throw ConnectTimeoutException
.
Post a Comment for "How To Find Server Unavailable In Android"