Multiple Download in One Persistent Connection

I made a Business App that download around 500 images at first start

Actually my App, do it, using 500 separate network.download( ) requests

This is not the best way to do it, the right way to do it it’s

  • Establish a persistent connection ( Connection: keep-alive )

  • Download 500 images 

  • Close the connection

There is a way to do it with the network API ?

I am unaware of a way to do that. I’ll ask Engineering.

Rob

We will need a feature request for this: http://feedback.coronalabs.com but can you put all those images in a .zip file, download the one zip file and then use the zip plugin to unzip them after the download completes?

Adding this sort of request streaming will take time and it’s not something easy to do.

Rob

I have faced same scenario in one of my project, 
I made a zip at server & download it in the documnet directory & then unzip it.

But in your case, if the size is more for 500 images even in a zip, Sometimes while download it will break/corrupt.
The best way for this can be maintaining a buffer & download packets.

I don’t know whether Corona supports but it might a solution if we find those.

Assif

 

Hi Rob,

thank you for your quick reply.

About your .zip workaround it’s not applicable, because different devices download different set of images

But now come the interesting thing

I tried to see how many different connection the Corona Simulator does.

With my big surprise, although I send the request for 300 image files, it establish just 6 / 7 connection and not more

Looking the transferred amount of data, I have seen that the most of the data go through just 1 connection

Then I tried to force “keep-alive” connections, using a parameter in the request like this:

local headers = {} headers["Connection"] = "keep-alive"; local params = {} params.headers = headers; params.progress = true; network.download(remotePath..ImageToDownload, "GET", downloadNewToDownload\_Listner, params, ImageToDownload, system.DocumentsDirectory );

NEW SURPRISE  :o

Monitoring again the connection, something it’s changed

Now there are 6 different connections too, but now all the data are almost equal distribuite on any connection

  :rolleyes:

What do you think about that Rob ?

Maybe could be interesting do some test on real devices

Thank you for your time 

Giorgio

You don’t want to open 300 simultaneous connections to your web server. It would take just a couple of users to jam your server.  Web browsers generally don’t open more than 8 at the same time.  Even if you could, you only have fixed amount of bandwidth and downloading 300 files at once or 1 at a time, the duration will practically be the same. 

It sounds like you have a pretty optimal configuration now.

Rob

I am unaware of a way to do that. I’ll ask Engineering.

Rob

We will need a feature request for this: http://feedback.coronalabs.com but can you put all those images in a .zip file, download the one zip file and then use the zip plugin to unzip them after the download completes?

Adding this sort of request streaming will take time and it’s not something easy to do.

Rob

I have faced same scenario in one of my project, 
I made a zip at server & download it in the documnet directory & then unzip it.

But in your case, if the size is more for 500 images even in a zip, Sometimes while download it will break/corrupt.
The best way for this can be maintaining a buffer & download packets.

I don’t know whether Corona supports but it might a solution if we find those.

Assif

 

Hi Rob,

thank you for your quick reply.

About your .zip workaround it’s not applicable, because different devices download different set of images

But now come the interesting thing

I tried to see how many different connection the Corona Simulator does.

With my big surprise, although I send the request for 300 image files, it establish just 6 / 7 connection and not more

Looking the transferred amount of data, I have seen that the most of the data go through just 1 connection

Then I tried to force “keep-alive” connections, using a parameter in the request like this:

local headers = {} headers["Connection"] = "keep-alive"; local params = {} params.headers = headers; params.progress = true; network.download(remotePath..ImageToDownload, "GET", downloadNewToDownload\_Listner, params, ImageToDownload, system.DocumentsDirectory );

NEW SURPRISE  :o

Monitoring again the connection, something it’s changed

Now there are 6 different connections too, but now all the data are almost equal distribuite on any connection

  :rolleyes:

What do you think about that Rob ?

Maybe could be interesting do some test on real devices

Thank you for your time 

Giorgio

You don’t want to open 300 simultaneous connections to your web server. It would take just a couple of users to jam your server.  Web browsers generally don’t open more than 8 at the same time.  Even if you could, you only have fixed amount of bandwidth and downloading 300 files at once or 1 at a time, the duration will practically be the same. 

It sounds like you have a pretty optimal configuration now.

Rob