http connection timeout issues http connection timeout issues android android

http connection timeout issues


Not sure if this helps you, however I think it's worth sharing here. While playing with the timeout stuff I found there is a third timeout type you can assign:

// the timeout until a connection is establishedprivate static final int CONNECTION_TIMEOUT = 5000; /* 5 seconds */// the timeout for waiting for dataprivate static final int SOCKET_TIMEOUT = 5000; /* 5 seconds */// ----------- this is the one I am talking about:// the timeout until a ManagedClientConnection is got // from ClientConnectionRequestprivate static final long MCC_TIMEOUT = 5000; /* 5 seconds */...HttpGet httpGet = new HttpGet(url);setTimeouts(httpGet.getParams());...private static void setTimeouts(HttpParams params) {    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,         CONNECTION_TIMEOUT);    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, SOCKET_TIMEOUT);    params.setLongParameter(ConnManagerPNames.TIMEOUT, MCC_TIMEOUT);}


I've met the same problem, I guess maybe the Android doesn't support this parameter.In my case i tested all three parameters for the ThreadSafeClientConnManager

params.setParameter( ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(20) );params.setIntParameter( ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 200 );params.setLongParameter( ConnManagerPNames.TIMEOUT, 10 );ThreadSafeClientConnManager connmgr = new ThreadSafeClientConnManager( params );

The first and second worked fine, but the third didn't work as documented. No exception was thrown and the executing thread was blocked indefinitely when the DefaultHttpClient#execute() was executing.

see http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e650
"...One can ensure the connection manager does not block indefinitely in the connection request operation by setting 'http.conn-manager.timeout' to a positive value. If the connection request cannot be serviced within the given time period ConnectionPoolTimeoutException will be thrown."


Thread t=new Thread(){  public void run()  {    try     {      Thread.sleep(absolutetimeout);      httpclient.getConnectionManager().closeExpiredConnections();      httpclient.getConnectionManager().closeIdleConnections(absolutetimeout,TimeUnit.MILLISECONDS);      httpclient.getConnectionManager().shutdown();      log.debug("We shutdown the connection manager!");    }    catch(InterruptedException e)    {}  }};t.start();HttpResponse res= httpclient.execute(httpget);t.interrupt();

Is that along the lines of what you all are suggesting?

I'm not exactly sure how to cancel the execute once it has started, but this seemed to work for me. I'm not sure which of the three lines in the thread did the magic, or if it was some combination of all of them.