Not getting all the data over the cell network

  • We are seeing quite an odd situation in our app.  When running the app on an iPhone 4 with iOS 4.3.5 (other combinations also exhibit this behavior but I don't have the exact details at the moment) and forcing data traffic to go over the cell network, our URL data loading calls are often not returning the entire set of bytes.  Here is the code:

    Option 1: Basic
    NSData* data = [NSData dataWithContentsOfURL:mURL];

    Option 2: Check for return error
    NSError* error = nil;
    NSData* data = [[[NSData alloc] initWithContentsOfURL:mURL 0 error:&error] autorelease];

    Option 3: Use NSURLConnection
    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:mURL];
    NSHTTPURLResponse* response = nil;
    NSError* error = nil;
    NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSInteger responseStatus = [response statusCode];

    NSLog(@"response code: %d", responseStatus);
    NSLog(@"response headers: %@", [response allHeaderFields]);

    Returns the following info every time:

    2012-08-08 11:54:20.815 App[994:8207] response code: 200
    2012-08-08 11:54:20.817 App[994:8207] response headers: {
        "Accept-Ranges" = bytes;
        "Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
        "Content-Encoding" = gzip;
        "Content-Length" = 87187;
        "Content-Type" = "application/pdf";
        Date = "Wed, 08 Aug 2012 18:54:20 GMT";
        Expires = "Thu, 19 Nov 1981 08:52:00 GMT";
        P3p = "CP=\"NOI DSP COR CUR IVD OTPi OUR STP INT\", policyref=\"/w3c/p3p.xml\"";
        Pragma = "no-cache";
        Server = "Apache/2.2.3 (CentOS)";
        "Set-Cookie" = "fromovÞleted; expires=Tue, 09-Aug-2011 18:54:19 GMT; path=/";
        Vary = "Accept-Encoding";
    }

    Option 4: Try on main thread
    NSMutableData* storageData = [NSMutableData data];
    [self performSelectorOnMainThread:@selector(loadURL:) withObject: storageData waitUntilDone:YES];

    - (void) loadURL:(NSMutableData*) storageData
    {
    NSData* data = [NSData dataWithContentsOfURL:mURL];
    [storageData appendData:data];
    }

    What we see is that occasionally (25% of the time?) the app loads all 87187 bytes, but the rest of the time, the app loads less data and no error or any other condition is ever returned.

    Does anyone have any idea what could be going wrong and perhaps what is the recommended approach to consistently and correctly loading data over the cell network?

    -Stevo Brock
    Sunset Magicwerks, LLC
    www.sunsetmagicwerks.com
    818-609-0258
  • On Aug 8, 2012, at 12:19 PM, Stevo Brock <devlists...> wrote:

    > What we see is that occasionally (25% of the time?) the app loads all 87187 bytes, but the rest of the time, the app loads less data and no error or any other condition is ever returned.

    How much less data? Is it just truncated, or is it the wrong data entirely?

    Also, exactly which cell network is this? Anything special about the server?

    My guess is that it's something going on with the cell network; a lot of them use proxies.

    Finally, the macnetworkprog list on this site is the best place to ask this; you have a better chance of reaching the Apple networking gurus.

    —Jens
  • Hi Jens,

    Thanks for pointing me to the other list.  I'll continue the conversation over there.

    To answer your questions quickly here:

    Generally around 10% of the data doesn't arrive, and it's a different amount every time.

    As far as I can tell the data is truncated.

    AT&T cell network here.  Unknown at another test location, but checking.

    -Stevo Brock
    Sunset Magicwerks, LLC
    www.sunsetmagicwerks.com
    818-609-0258

    On Aug 9, 2012, at 11:37 PM, Jens Alfke wrote:

    >
    > On Aug 8, 2012, at 12:19 PM, Stevo Brock <devlists...> wrote:
    >
    >> What we see is that occasionally (25% of the time?) the app loads all 87187 bytes, but the rest of the time, the app loads less data and no error or any other condition is ever returned.
    >
    > How much less data? Is it just truncated, or is it the wrong data entirely?
    >
    > Also, exactly which cell network is this? Anything special about the server?
    >
    > My guess is that it's something going on with the cell network; a lot of them use proxies.
    >
    > Finally, the macnetworkprog list on this site is the best place to ask this; you have a better chance of reaching the Apple networking gurus.
    >
    > —Jens
previous month august 2012 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today