Tuesday, July 31, 2012

[android-developers] Re: Transporting to Server Problems

If you are "getting a variety of" errors, as opposed to a single reproducible error, it could indeed be something goofy with your connection.  Why not at least switch to a solid Wifi connection so you can eliminate that possibility?


On Tuesday, July 31, 2012 8:35:42 AM UTC-5, Evan Ruff wrote:
Hey guys,

I'm having some trouble getting my phone collected data up to my servers. I thought that I was getting old fashioned SocketTimeouts due to the phones having a bad connection or something of the like. After jacking up the timeouts WAY up on the phone (120 seconds) and the timeout WAY up on the server (120 seconds) I think that I must be doing something wrong in my code.

After changing the timeouts, I am now getting other odd timeout exceptions on the server. I'm getting a variety of "Unexpected EOF read on the socket", "java.io.IOException: Invalid CRLF" and the venerable "java.net.SocketTimeoutException". I'm wondering if I'm not properly flushing or clearing out the connection/entity in the Service logic. I was hoping someone could point out what I was doing wrong.

My data-sending code is as follows:
DefaultHttpClient httpClient = Util.getHttpClient(); // nothing special, just sets the timeouts

HttpPost httpPost = new HttpPost( Moose.getServerAddress() );
ByteArrayOutputStream baos = new ByteArrayOutputStream();

// Write out the payload using Jackson to the baos

ByteArrayEntity baEntity = new ByteArrayEntity( baos.toByteArray() );
baEntity.setContentType("application/json");
baEntity.setChunked( true );
httpPost.setEntity( baEntity );

HttpResponse response = httpClient.execute( httpPost );
HttpEntity entity = response.getEntity();

I'm not doing any cleanup at all, and I think that might be my problem. Is there a correct way to terminate this off? I assume I should be closing the  ByteArrayOutputStream, but what about the ByteArrayEntity? Do I need to do anything with the response after I'm doing consuming it?

Thanks for any help and suggestions!

E

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment