NSURLConnection and buffering
-
I'm using NSURLConnection to download a web page which is served from a
server that uses HTTP 1.1 and chunked encoding. The web page consists of 2
sections; the server sends the first section which is about 300 bytes
immediately, and has to do some processing for 30 seconds before it sends
the next chunk which is larger (10KB).
I'd like to display the first 300 bytes immediately, but my delegate method
connection::didReceiveData is not called until after the second chunk is
sent by the server (that is 30 seconds later). It appears there is a minimum
buffer size in the NSURLConnection class - it won't give the bytes to me
until it has accumulated that many bytes.I verified this by increasing the
size of the first chunk. If is is 2KB or so, then I get the didReceiveData
call right after the server has sent the first chunk.
I noticed that Safari on Macbook pro has the same behavior. It won't render
the first chunk until after the second one is sent.
Any way to tell NSURLConnection to not buffer and send me bytes immediately?
Arvind -
On Fri, Jul 4, 2008 at 4:34 AM, Arvind Jain <arvind...> wrote:
> I'm using NSURLConnection to download a web page which is served from a
> server that uses HTTP 1.1 and chunked encoding. The web page consists of 2
> sections; the server sends the first section which is about 300 bytes
> immediately, and has to do some processing for 30 seconds before it sends
> the next chunk which is larger (10KB).
>
> I'd like to display the first 300 bytes immediately, but my delegate method
> connection::didReceiveData is not called until after the second chunk is
> sent by the server (that is 30 seconds later). It appears there is a minimum
> buffer size in the NSURLConnection class - it won't give the bytes to me
> until it has accumulated that many bytes.I verified this by increasing the
> size of the first chunk. If is is 2KB or so, then I get the didReceiveData
> call right after the server has sent the first chunk.
>
> I noticed that Safari on Macbook pro has the same behavior. It won't render
> the first chunk until after the second one is sent.
> Any way to tell NSURLConnection to not buffer and send me bytes immediately?
Are you sure that the data is even being sent when you want it to be?
Until you've verified that it's making it onto the network by looking
at the traffic with a network sniffer, I would hesitate to start
assigning blame and debugging anything.
Mike -
>
> Date: Fri, 4 Jul 2008 19:22:30 -0400
> From: "Michael Ash" <michael.ash...>
> Subject: Re: NSURLConnection and buffering
> To: "Cocoa Developers" <cocoa-dev...>
> Message-ID:
> <da8fe1600807041622k763d2570n10d2c9e2c4f4d03d...>
> Content-Type: text/plain; charset=UTF-8
>
> On Fri, Jul 4, 2008 at 4:34 AM, Arvind Jain <arvind...> wrote:
>> I'm using NSURLConnection to download a web page which is served from a
>> server that uses HTTP 1.1 and chunked encoding. The web page consists of
> 2
>> sections; the server sends the first section which is about 300 bytes
>> immediately, and has to do some processing for 30 seconds before it sends
>> the next chunk which is larger (10KB).
>>
>> I'd like to display the first 300 bytes immediately, but my delegate
> method
>> connection::didReceiveData is not called until after the second chunk is
>> sent by the server (that is 30 seconds later). It appears there is a
> minimum
>> buffer size in the NSURLConnection class - it won't give the bytes to me
>> until it has accumulated that many bytes.I verified this by increasing
> the
>> size of the first chunk. If is is 2KB or so, then I get the
> didReceiveData
>> call right after the server has sent the first chunk.
>>
>> I noticed that Safari on Macbook pro has the same behavior. It won't
> render
>> the first chunk until after the second one is sent.
>> Any way to tell NSURLConnection to not buffer and send me bytes
> immediately?
>
> Are you sure that the data is even being sent when you want it to be?
> Until you've verified that it's making it onto the network by looking
> at the traffic with a network sniffer, I would hesitate to start
> assigning blame and debugging anything.
>
> Mike
>
>
Yes the server has sent the bytes to the client. I did do a tcpdump to
verify. Also, Firefox was able to render the first chunk whereas Safari as
well as my application couldn't.



