Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid HttpClient and JSON-RPC server gets no response and keeps retrying over EDGE
    primarykey
    data
    text
    <p>This one has been driving me crazy for a few days. It is very difficult to explain and understand, but I'll do my best. Please ask any questions if I'm unclear anywhere. This problem only happens when I'm sending a large packet, something over 300Kb, like an image. Sending smaller packets work fine.</p> <p>I have an Android Service that communicates with a Python-based JSON-RPC server. When communicating over WiFi or 3G everything works fine. However, when communicating over EDGE everything goes horribly wrong. The Android app creates an HttpClient and HttpPost. The request is made, however a response is never received from the server. I've put some log statements before and after the 'execute' request, and it never goes past that. It also appears that the request is made AGAIN if the initial attempt was unsuccessful. I've got log statements in each of the "catch" blocks, and none of them are executed, so it seems the HTTP request is made again internally somehow.</p> <p>I've been examining the RPC code on my server and here's what I can tell from there. The socket connection is made and data is read from the socket. Examining netstat shows the established connection for a few seconds, then it goes into CLOSE_WAIT. As soon as that happens no more data is read from the socket (obviously) and the server sits in a continuous loop until the socket connection is terminated. At this point I've been killing the JSON-RPC service and keeping it off. If I don't kill it, the service will take up 100% of the CPU and I've let it sit for about 5 minutes and it didn't appear to shutdown the socket.</p> <p>Here is the code to make the RPC call from the Android device:</p> <pre><code>DefaultHttpClient client = new DefaultHttpClient(); try { HttpPost post = new HttpPost(url); post.setHeader("Content-Type", "application/json"); post.setEntity(new ByteArrayEntity(data)); // I tried these lines on the HttpPost but didn't seem // to make a difference. HttpProtocolParams.setVersion(client.getParams(), HttpVersion.HTTP_1_1); HttpProtocolParams.setUseExpectContinue(client.getParams(), false); // This doesn't seem to do anything at all... client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); Log.d("MyAppName", "** About to make HTTP request"); String json = client.execute(post, new BasicResponseHandler()); Log.d("MyAppName", "** Returned from HTTP request!"); JSONObject obj = new JSONObject(json); if (obj.isNull("result")) { rtnval = obj.getJSONObject("error").getString("message"); } else { // More code here... } } catch (ClientProtocolException cpe) { Log.e("MyAppName", "EXCEPTION: " + cpe.getMessage()); } catch (IOException ioe) { Log.e("MyAppName", "EXCEPTION: " + ioe.getMessage()); } catch (JSONException je) { Log.e("MyAppName", "EXCEPTION: " + je.getMessage()); } finally { client.getConnectionManager().shutdown(); } </code></pre> <p>The "offending" code on the RPC side is actually in (Python2.7) SimpleXMLRPCServer.py in the while loop at line #487. The line "self.rfile.read" is what continuously gets 0 bytes which never decrements size_remaining and thus never leaves the loop. I'm not too concerned about that, I'd really like to know why the connection is getting killed, but I added that in the question for completeness sake.</p> <p>So I'm trying to figure out how the HTTP connection is going into CLOSE_WAIT. It appears to be coming from the Android device, but I can't seem to figure it out for sure. I've tried setting the ByteArrayEntity to be chunked, but that appears to omit the "Content-Length" header which is required by JSON-RPC. </p> <p>If someone has any idea what I can do to keep that connection open longer or prevent it from being closed I'd greatly appreciate it. I'd also like to prevent the HTTP request from being retried as well. Thank you for any help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload