Hi.
If I make myself a test downloading data with AsyncTask via the
DefaultHttpConnection and run the test in a loop with 20 iterations I
always get one or two socket timeouts.
Does anyone know the reason for the timeout? Is this related to Http
connection management issues? I have tried both the DefaultHttpClient
with default connection manager and the pooled connection manager
below. I get the same result for both of them. I have changed URLs to
various external sites and it seems related to the client and not the
server so I guess my code has a flaw somewhere and I would greatly
appreciate anyone finding it :-)
My code:
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(
new Scheme("http",
PlainSocketFactory.getSocketFactory(),
80));
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 15000;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
int timeoutSocket = 25000;
HttpConnectionParams.setSoTimeout(httpParameters,
timeoutSocket);
cm = new ThreadSafeClientConnManager(httpParameters,
schemeRegistry);
httpclient = new DefaultHttpClient(cm, httpParameters);
AsyncTask implementation:
protected String doInBackground(UrlParams... params)
{
UrlParams param = params[0];
this.url = param.url.toExternalForm();
HttpGet httpget = new HttpGet(this.url);
String responseBody = "";
try
{
// Execute the HTTP GET
HttpResponse response = httpclient.execute(httpget);
InputStream responseStream = null;
if (response.getEntity() != null)
{
responseStream =
response.getEntity().getContent();
}
...
responseStream.close();
responseBody = buffer.toString();
}
catch (ClientProtocolException e1)
{
return "";
}
catch (IOException e1)
{
return "";
}
...
}
W/System.err( 7281): java.net.SocketTimeoutException: The operation
timed out
W/System.err( 7281): at
org.apache.harmony.luni.net.PlainSocketImpl.read(PlainSocketImpl.java:
557)
W/System.err( 7281): at
org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:
87)
W/System.err( 7281): at
org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java
:103)
W/System.err( 7281): at
org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:
1
91)
W/System.err( 7281): at
org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:
82)
W/System.err( 7281): at
org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:
174)
W/System.err( 7281): at
org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientCon
nection.java:179)
W/System.err( 7281): at
org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnecti
on.java:235)
W/System.err( 7281): at
org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnA
dapter.java:259)
W/System.err( 7281): at
org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:
279)
W/System.err( 7281): at
org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:
121)
W/System.err( 7281): at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:
410)
W/System.err( 7281): at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:
555)
W/System.err( 7281): at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:
487)
W/System.err( 7281): at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:
465)
W/System.err( 7281): at
mypackage.AsyncHttp.doInBackground(AsyncHttp.java:67)
W/System.err( 7281): at
mypackage.AsyncHttp.doInBackground(AsyncHttp.java:1)
W/System.err( 7281): at android.os.AsyncTask$2.call(AsyncTask.java:
185)
W/System.err( 7281): at java.util.concurrent.FutureTask
$Sync.innerRun(FutureTask.java:256)
W/System.err( 7281): at
java.util.concurrent.FutureTask.run(FutureTask.java:122)
W/System.err( 7281): at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:648)
W/System.err( 7281): at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:673)
W/System.err( 7281): at java.lang.Thread.run(Thread.java:1060)
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en