Firing Multiple HTTP ASYNC calls cancels previous request

Hi All,

I am trying to achieve a case of firing multiple http requests ( async ) one after another in a loop to receive content asynchronously whenever they arrive but when i try with roUrlTransfer it seems to cancel the previous request and succeeds only when for the last request. Could a case like this be doable at all ? Any suggestions to implement a case like this is welcome.

Here’s my code :


port = CreateObject("roMessagePort")

uri = [ "http://www.naturalengland.org.uk/Images/drywalls_tcm6-9377.jpg", "http://www.visual-arts-cork.com/images-paint/constable-haywain.jpg" ]

for each imgURI in uri
        imgObj = { id: invalid, bitmap: invalid, size: { w: 200, h: 200 }, uri: imgURI, status: invalid } 
        images.push(imgObj)
    end for
    
    ' Request Images through roURL
    for each img in images
        ' Tried it without having http = invalid. Produced the same result.
        http = invalid
        http = CreateObject("roUrlTransfer")
        http.SetPort(port)
        http.SetUrl(img.uri)
        filePath = "tmp:/" + util_md5(img.uri)
        img.status = http.AsyncGetToFile(filePath)
        print "Status is "; img.status
        img.id = http.GetIdentity()
    end for  

While True
        
        msg = wait(0, port)
        textureFlag = false
        
        if msg <> invalid
                
            if (type(msg) = "roUrlEvent")
                
                code = msg.GetResponseCode()
                print "Code is "; code
                if code = 200
                    textureFlag = true
                    for each img in images
                        if img.id = msg.GetSourceIdentity()
                            img.bitmap = true
                        end if
                    end for
                else if code = -10001
                    print "Error is"; msg.GetFailureReason()
                end if
                  
            end if
        
        end if
        
        
    End While

I’m making a guess here, but you do set ‘http’ to invalid in the request loop… and I think at that point all bets are off as to what happens to whatever that http roUrlTransfer was doing, if the request even lived to get made in the first place.

Which sounds about right because the last one seems to ‘live’.

So, if you wanted to put your http requests in some sort of array and push them sequentially…it might work-out?

Please use the [ code][/code] tags when posting code. It makes is so much easier to read.

The problem with your code is that you’re invalidating “http” on each pass through the loop. That’s what’s cancelling the previous async request. You should instead be storing the roUrlTransfer objects in an array to keep them in scope.