Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jimalso
Level 8

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.

url="http://<-webpage-address->info.txt"
settings=getFileString(url)
...

function getFileString(url)
  timeout=1000
  fileString=""
  http = CreateObject("roUrlTransfer")
  http.SetPort(CreateObject("roMessagePort"))
  http.SetUrl(url)
  if http.AsyncGetToString()
    event = wait(timeout, http.GetPort())
    if type(event) = "roUrlEvent" then
      fileString = event.GetString()
    elseif event = invalid then
      http.AsyncCancel()
    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
1 REPLY 1
RokuKC
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