Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
mrkjffrsn
Visitor

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

0 Kudos
2 REPLIES 2
dcrandall
Visitor

Re: Firing Multiple HTTP ASYNC calls cancels previous reques

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?
0 Kudos
TheEndless
Channel Surfer

Re: Firing Multiple HTTP ASYNC calls cancels previous reques

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.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.