I am using simple urlconnection like this:
url = URL+"getClient&uid="+cl_id;
URL url = new URL(this.url);
Log.d("Set++","get_t URL: "+ url);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
its working fine, but sometimes i get this error:
error: java.net.SocketTimeoutException: Connection timed out
what could be the reason? I have only 4 clients... so i dont think that the server is overloaded with connections.
the code:
try {
URL = Settings.BASE_URL + "_interface.php?" +
"key=" + Settings.KEY +"&app_naam="+Settings.APP_NAAM+ "&action=check&setTime="+c;
URL url = new URL(URL);
if(D)Log.e("ChekTreadAanvr+url", URL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
BufferedReader rd = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String response;
if ((response = rd.readLine()) != null) {
rd.close();
}
if(D) Log.d("WebSaveThread+","DATARESIEVED: "+response);
return response;
} catch (MalformedURLException e) {
if(D)Log.d("ERR","server chekc failure ++ ");
return success = false;
} catch (IOException ioex) {
if(D)Log.e("ERR", "error: " + ioex.getMessage(), ioex);
success = false;
}
return Boolean.toString(success);
It may be possible that your Internet Connection Speed is weak. You can increase your Timeout Interval by using following method.
httpURLConnection.setConnectTimeout( 6 * 10 * 1000 ); // One Minute
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With