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: 
dcrandall
Visitor

AsyncPostFromString, do I need to wait for a response?


url = "http://someurl.com"

request = CreateObject("roUrlTransfer")

if(debug)
'We always need to set a port, or the request won't get made.
port = CreateObject("roMessagePort")
request.SetMessagePort(port)
endif

request.SetUrl(url)

request.AddHeader("Content-Type", "application/xml")

outstanding = request.AsyncPostFromString(dataRequest)

if(debug = true)
msg = wait(50000, port)
endif


If 'debug' is false, I don't seem to be making the request. If debug is true, the request registers on the other side. Is it just not setting the port that is hosing me, or is it not setting the port and not waiting for the message that's hosing me?

Normally I don't care about the response, as I'm making API requests to omniture... long as it works once, I don't care if something breaks in the field as long as it doesn't crash the app. But I turned 'debug' off, and I look to see no omniture data for like the last week (oops).
0 Kudos
4 REPLIES 4
TheEndless
Channel Surfer

Re: AsyncPostFromString, do I need to wait for a response?

Without seeing the full code, it's hard to say for sure, but my guess would be that "request" is going out of scope before the request can be issued. If that happens, the request will get cancelled when the garbage collector does its thing.
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
dcrandall
Visitor

Re: AsyncPostFromString, do I need to wait for a response?

Now that you mention it, the request TOTALLY leaves scope.

/hits self in head.

This is the second question about requests not getting made due to scope I've seen in a week... and it was my fault. 😉

Now, to keep this in scope... there isn't a klever way to handle this that someone knows without thinking too hard about it, is there? I'm tempted to hand it to a global object and let it exist, although it sounds kind of leaky.

EDIT: I have a 'class' that ultimately calls this function. I can basically preserve the request within the class as a pseudo member-variable... it's kind of ham-fisted, but it totally works.
Defensive software engineering FTW.
0 Kudos
RokuMarkn
Visitor

Re: AsyncPostFromString, do I need to wait for a response?

Storing the object in a global is only slightly leaky, since you can only leak one object. It does have the risk that if you make a second request before the first one finishes, you'll again cancel the outstanding request. A "correct" way to handle it would be to keep all outstanding requests in an AA. Occasionally (probably whenever you make a new request), read each roUrlEvents from the message port and remove the ones from the AA that have finished. This full complexity isn't always needed, but it's actually only a few lines of code and it's probably worth doing right.

--Mark
0 Kudos
TheEndless
Channel Surfer

Re: AsyncPostFromString, do I need to wait for a response?

I typically store the roUrlTransfer objects in an associative array (by the GetIdentity() value), then process all completed requests after each new request (and in some scenarios on a timer).

EDIT: yeah, what RokuMarkn said.. 😛
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