IOS Socket

I have a socket which downloads a file with my blog data as follows.
I split the file into an array to load (no problem so far)

3 'number of post
photo url
text url
photo url
text url
photo url
text url

When I try and FileLoaderSocket2 I get errors because socket 1 hasn’t finished receiving the info I am guessing

// If the authentication request was successful…
If HTTPStatus = 200 Then

// Convert the response content to text.
URL = Xojo.Core.TextEncoding.UTF16LittleEndian.ConvertDataToText(Content)
Lines() = URL.Split(&u0A)

Dim a As text
a = lines(0).right(1)
newsfeedtotal = Integer.FromText(a)

dim b as text
for x as integer = 0 to NewsFeedTotal-1
b = “”+x.ToText + “.jpg”
FileLoaderSocket2.Send(“GET”, a)
next x

End If

What would be the a more efficient approach given that I need to download the first file to see how many picture and text files need to be subsequently downloaded?

Your problem is probably in this section:

for x as integer = 0 to NewsFeedTotal-1 b = ""+x.ToText + ".jpg" FileLoaderSocket2.Send("GET", a) next x
A socket can’t have more than one request going on at a time.

That should also be

FileLoaderSocket2.Send("GET", b)

Thanks Greg,

If you can’t loop a socket request how could you load multiple files or how do you know when the socket has finished loading so you can reuse it?


Usually people create more than one socket or they use a method. I swear I just typed this in another thread…

  1. Make a property, let’s say URLs() as Text stored on the view or globally somewhere.
  2. Make and push all of the urls into the array
  3. Make a method which pulls element 0 from the array, removes it from the array and sends the request.
  4. In the FileReceived event use Xojo.Core.Timer.CallLater to call the method in step 3 to retrieve the next file.

Thanks Greg :slight_smile: