I have an Android app that communicates with a server via asynchronous socket connection to transfer somewhat large packets of information (up to 11 Megs). In order to accommodate for this interactions I have placed small sleeps in key points of the data sending and receiving. On WiFi the connection works. Do to the size of the information one read or write doesn’t seem to be sufficient but I have created functions to keep reading off the socket until the transfer is finished.
As I said all of this works on WiFi. However, on 3G or edge networks the transfer fails, interrupts midway, and generally is buggered. I have placed numerous checks and sleeps to ensure that information is given the opportunity to pass, however it fails to.
Unfortunately it is difficult to be clearer as to the source of the problem. I have worked for several days trying to clear up this problem as elegantly as possible with no avail.
TLDNR WiFi is able to send data but mobile networks fail. I need to know why and how to fix it.
Thank you.
The actual problem turned out to be that the amount received per
read()was substantially smaller then I had expected. My program required the entire schema to be sent via XML before the program knew how to use it. It wasn’t receiving enough of the string, and so would die. Now it checks for if the /schema tag is in the string (via if (!response.contains("/schema"))) and does not stop reading until it finds that or times out.