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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Channel Surfer

AsyncGetToString works well on Express but poorly on Ultra

I use the following code get the contents of a small (<100 bytes) text file whose content may change frequently; it is checked multiple times per minute.


function getFileString(url)
  http = CreateObject("roUrlTransfer")
  if http.AsyncGetToString()
    event = wait(timeout, http.GetPort())
    if type(event) = "roUrlEvent" then
      fileString = event.GetString()
    elseif event = invalid then
    end if
  end if
  return fileString
end function

On a Roku Express I get a non blank return (the contents of the info.txt file) on virtually every call to getFileString(). A Roku Ultra call to getFileString() almost always returns a blank string ""; i.e. it could take one or more typically hundreds of calls (sometimes never) to get a non-blank string return.

My roku specifics:
3910RW Roku Express, software 10.0.0 build 4209-51
4670X Roku Ultra, softwate 10.0.0 build 4209-46

Why does this work consistently well on the Express but almost always fail on the Ultra?


0 Kudos
Roku Employee
Roku Employee

Re: AsyncGetToString works well on Express but poorly on Ultra

When it comes to asynchronous events and network operations, you shouldn't expect things to always be the same on different devices, or even on the same device from run to run.  The network connection timing can be different, the processor speed or number of processors can be different, different background processing can be going on, etc.

I can't guess specifically on what you're seeing, but the code that does a single Wait call isn't really correct.  Maybe it's taking longer than a second, or it's getting interrupted before the timeout for some reason.  Did you try setting the timeout to a larger value such as 5 seconds or more, to see if that made any difference?

I don't know if your code is just sample code, because it is assuming that AsyncGetToString is going to work the same as synchronous GetToString, which you wouldn't generally want in real channel code.

Usually, you will have a loop that is polling the message port in your application event processing or task.  And if Wait returns an invalid, it should just loop and wait again.  Then, rather than using a fixed small timeout like that, you might want to wait with 0 so it wakes up just when necessary, or if you want it to poll it every second, at least keep retrying and use a separate time counter if you really need special timeout behavior.

Hope that helps.

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.