Downloading file(s) in a loop

I have the error (screenshot below) using the URLConnexionGET example.

So, I add:

Sub ReceivingProgressed(bytesReceived As Int64, totalBytes As Int64, newData As String) Handles ReceivingProgressed
  If bytesReceived = totalBytes Then
    Me.Disconnect
  Else
    System.DebugLog Str(bytesReceived) + " bytes received on a total of " + Str(totalBytes) + " bytes."
  End If
End Sub

In the WebConnexion Class (URLConnection). But I continue to get that message.

A solution ?

Donā€™t reuse the socket

1 Like

The only code related to a socket is:

WebConnection.Send(ā€œGETā€, URLField.Text)

Are you working with Android?

Or you are using the Desktop example called ā€˜Using GET with URLConnectionā€™?

Donā€™t do that.

Once a file is received, the FileReceived() event is fired.
In case of something off an Error() event will be fired

You probably wonā€™t need to use disconnect. After receiving or an error the connection ends.

Donā€™t trust bytesReceived as a sign of ā€œdoneā€.

2 Likes

No, it is a Desktop project example from Xojo.

I can ask manually more than one file (if I change the URL and click in the button - no change in the example), but I want to make a batch download passing URLs with dates.

Now thatā€™s the morning, mlaybe I will find a solutionā€¦

It does not change anything. Still an inconsistent design.

For some reason you are trying another download with one in progress. You must wait the proper finishing or an error before a new download.

Bad time.

I was not able to go ahead.

The only bad solution (unusable) is to change the date manually, click in GET and click in a button I add so I can extract the data I really want.
If I only have to do it two or three timesā€¦ I have to do it n times 365, so this is an unusable solution.

I give up this project too.

Emile, could you use a timer and make one request every second?

Keep in mind that you may be limited by the OS in terms of how many simultaneous requests you can have going. You could however make a subclass of URLConnection that set a flag when FileReceived fires so you know when itā€™s done. Then if you have an array of running connections, use the timer to remove the ones that are ā€œdoneā€ and then create that many more from your queue. That way maybe you only have 10 at any given time, but your requests will run until completion.

1 Like

Please, donā€™t give up. It is great that you want to make things work on your own.

There are people that want to help you, the problem I see is that there can be some barriers between the information you provide and the information you receive.

From you original post, it seemed like the Example that comes with Xojo had problems but later you said you are modifying the example to download several URLs.

Of course, those who know understand the error and tried to help but maybe the information they provided is not enough for you to apply those ideas to your code.

I will say that if you provide a sample project (zip it and upload to this thread), someone (or several people) will give you specific code changes for your project to work.

1 Like

as i remember this class/object can only download data one by one.
request-response,request-response,request-response.

that is what the message said, you have a running request and start a new request before the previous was completed.

if you like to download parallel like a browser is doing you need more URLConnection objects.

Iā€™ll find some time tonight and will play with your problem. No promises, but usually I make those things work . :smile:

Maybe use curl. I use curl in a loop to get all my data files from the Internet. It never fails as long as the url is not changed by the owner.

Thatā€™s because curl creates a new connection every time. If you want to download multiple files in Xojo, create a new URLConnection every time.

2 Likes