开发者

Android https long polling: Cannot receive response when polling interval is longer than 70 seconds

I am trying to implement a long polling push-service on my android application (based on Microsofts AUTD ActiveSync -> http://technet.microsoft.com/en-us/library/aa997252.aspx).

I have already realised the server part with Servlets 3.0 running on Tomcat 7.0. I have tested my AsyncServlets with CURL, everything works fine.

That's how I tested my AsyncServlet:

curl "https://webservice.mydomain.net/push?id=1&heartbeat=180000" --insecure --user user:password -D -

Server response after 3 minutes (Heartbeat Interval)

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 01:00:00 CET
Content-Type: application/json;charset=ISO-8859-1
Content-Length: 0
Date: Sat, 15 Jan 2011 23:38:57 GMT

On my android application I used following code:

HttpParams httpParams = mDefaultHttpClient.getParams();
HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpParams, mHeartbeat + TIMEOUT_TOLERANCE);
mDefaultHttpClient.setParams(httpParams);

HttpGet httpGet = new HttpGet(mPushURL);
httpGet.addHeader("Accept", "application/json");

try {
    Log.i(TAG, "Executing GET(PUSH) request " + httpGet.getRequestLine());
    HttpResponse httpResponse = mDefaultHttpClient.execute(httpGet);
    Log.i(T开发者_运维问答AG, httpResponse.getStatusLine().toString());
    Log.i(TAG, convertInputStream(httpResponse.getEntity().getContent())); //For testing purposes
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

I ran several tests. If I use a 70 seconds heartbeat interval I receive the response. If I use a > 70 seconds heartbeat interval I receive (after the specified heartbeat interval) a SocketTimeoutException instead of my HTTP 200 OK Response. (To clarify: My set SocketTimeout(SoTimeout) is working correctly, but maybe the connection get lost, I have no idea why).

Thanks for every response.


Use URLConnection and set readTimeOut. Buy it is hard to say. i think android network layer is freezing open connections. (i am working on similar project. Could't find why open connections are freezing)


Try with adding:

ConnManagerParams.setTimeout(params, CONNECTION_TIMEOUT);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜