0

I have this issue that has caused me to pound my head against the wall. I am writing a newspaper app that parses data in JSON from a database and displays it. The app works fine and passes data on WiFi and 4G, but chokes on 3G. Most of the time it takes between 30 seconds and 1 minute to grab data on 3G while only taking one to two seconds on WiFi. I often receive a warning message stating: HttpHostConnectException: Connection refused. I know the site works perfectly fine and is not causing issues because I can query fine on WiFi and 4G along with navigating from a desktop just fine with no problems. As another test, I borrowed my coworkers MiFi which is only on 3G in our area, and connected my device to it, and it passes data just fine although it is only 3G back to the Internet. So after looking at this, and trying to find a solution, I have come to the conclusion that maybe I am not doing something right on my end. To the best of my knowledge, everything is fine, but I am no expert. Any insight on this would be greatly appreciated.

Summary--

  • 4G = Works
  • WiFI = Works
  • 3G = Extremely slow
  • 3G via WiFi(MiFi on 3G) =Works

    public JSONObject makeHttpRequest(String url, String method, List params) {

    // Making HTTP request
    try {
    
         if(method == "GET"){
            // request method is GET
            DefaultHttpClient httpClient = new DefaultHttpClient();
            String paramString = URLEncodedUtils.format(params, "utf-8");
            url += "?" + paramString;
            HttpGet httpGet = new HttpGet(url);
            HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();
            System.out.println("---GET--- Now grabing GET DATA");
        }           
    
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }
    
    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }
    
    // return JSON String
    return jObj;
    

    }

manlio
  • 18,345
  • 14
  • 76
  • 126
gbrewster
  • 163
  • 1
  • 3
  • 10

1 Answers1

0

Is the 3G on my MiFi equally slow? Cause otherwise it sounds like you are saying that your process fails where the connection is slow.

You mention that 3G takes > 30s. Are you running on app engine? GAE has a hard limit on how long transactions can take - I believe that limit is 30s.

What if you added a delay on your server so that even a Wifi request takes as long as 3G tests are taking now - to verify that it is the time taken that is causing the failure.

Also, I think those 3G results sound rather poor. I don't know how much data you are retrieving but it really doesn't sound like it should take that long. So perhaps your 3G connection is simply a poor quality connection (and the MiFi perhaps is a better 3G connection).

Tom
  • 17,103
  • 8
  • 67
  • 75
  • The MiFi is connecting to the tower at -69 dbm and is only on 3G, but passes data fine. So the MiFi is equally slow as compared to a phone. I have tried a tablet and a phone, and gotten the same issue. This is the average amount of data passed through http://pastebin.com/2PPRpkdw. – gbrewster Mar 08 '13 at 16:50
  • 30 seconds on 3G versus ~2s otherwise - something wierd is going on. I do JSON HTTP requests from Android to GAE server and they always complete in < 1s on 3G (unless server is cold). Have you measured the time on the server? – Tom Mar 08 '13 at 17:05
  • I cannot access the webserver since it is at is managed by a newspaper company, but I did set up a identical database for testing. When I connect to the test server, it works just fine, but it seems to be only when connecting to the live database, that I get issues (3G only. WiFi works great). I have tested on three devices as of now, and am still lost. It kind of points to a server issue in my book, but before I start making calls and asking questions to the newspaper company I wanted to make sure it wasn't my end. – gbrewster Mar 08 '13 at 19:58
  • Can your client make other requests, e.g. pinging Google, on 3G with normal round trip times? – Tom Mar 08 '13 at 21:53
  • Yes, it seems that everything else is working fine, except for this app. Even if I go through a web browser, the pages loads in seconds on 3G, just not through my app. – gbrewster Mar 08 '13 at 23:59
  • Okay, now I understand the need for the wall. I guess my best advice at this point would be foam padding. – Tom Mar 09 '13 at 00:23