user609530
user609530

Reputation: 51

Iphone capable to pause and resume downloading of files automactically in a multitasking enviroment

Recently I developed a simple file download application in Iphone. I was testing this in the Iphone 3gs and found something interesting.

I close the application, when it begins downloading the file. I opened back the application after some time (say 6 seconds), the download actually starts from where it has left behind.

How can the software be capable of pausing and resuming the http download. (My tomcat server does not has any streaming or resuming capability )

My Setup, Tomcat , with a Servlet which basically read from filesystem and send outs. Iphone 3gs, and simple file download application ,I have not enabled any UIBackgroundModes. a progress bar added to represent the state

Upvotes: 1

Views: 549

Answers (2)

sergio
sergio

Reputation: 69047

What you are witnessing is a matter of connection timeout not firing during the time your app has not been active. In some more detail:

  1. when you open a connection and start transferring data across it, the OS associate to the connection a timeout (which is say 90 sec, 60 sec, 300 sec, depending on some setting that you can generally tweak, although not always easily);

  2. this timeout is used to monitor the connection state; if no data is transferred for a period longer than the timeout, then the connection is deemed broken, or it is assumed that it has been closed by the other party;

  3. this is necessary because a remote connection is highly variable in quality and if you inspect your transfer you will notice that they can "easily" stop for a few seconds, or even more;

  4. if data transmission stops for a while, but resumes before the connection time out fires, the network protocols (all of them, client-side and server-side) are able by design to resume data transfer as there had been no interruption (network protocols have specific features dealing with that, like chunking your data into smaller packets and numbering each packet to ensure that all of them are trasmitted and that it is possible to rearrange them according to the sending order if anything went astray in the communication);

So this should explain the fact that your app after a 6 seconds halt did resume the connection without a hitch.

If you let you app closed for a longer period of time, you will see that the connection will break.

Upvotes: 2

James Eichele
James Eichele

Reputation: 119184

Slicing large data up into small portions is a basic feature of the HTTP standard. See HTTP1.1 - Section 14.16 - Content-Range for details. The Cocoa implementation more than likely handles all of this by default. A large download will be cached during transmission and automatically resumed on request.

The server and the iPhone don't really need any extra software to support this feature. In the context of HTTP communication, every download is just a number of data packets sent out from the server, and any of these packets can take a long time to actually reach the receiving device. A resumed download is really just the same download, with an unusually long delay between packets.

Upvotes: 0

Related Questions