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: 
matrixebiz
Roku Guru

Brightscript Timeout settings _getUrlToString

Hello, I have a link to a URL in my code and I was wondering if I can change the timeout if the URL is unreachable to be shorter than 30 seconds? The URL is being sent to the parse routine even thought it is invalid so where in the parseXmlDocument function can I set the timeout? Thx
 _getUrlToString. roUrlEvent. Int: 1. ResponseCode: -28. FailureReason: Connection timed out after 30001 milliseconds.
0 Kudos
11 REPLIES 11
EnTerr
Roku Guru

Re: Brightscript Timeout settings _getUrlToString

See if setMinimumTransferRate() does it for you.
0 Kudos
belltown
Roku Guru

Re: Brightscript Timeout settings _getUrlToString

In Parse.brs  (line 48) change:


' Read the Xml document from either a local file or a remote url
xmlString = _getPathToString (xmlPath)


to:


' Read the Xml document from either a local file or a remote url
xmlString = _getPathToString (xmlPath, 5000)


where the 2nd parameter is the maximum number of milliseconds you want to wait for (5000ms = 5 seconds).
0 Kudos
matrixebiz
Roku Guru

Re: Brightscript Timeout settings _getUrlToString

Thank you
0 Kudos
belltown
Roku Guru

Re: Brightscript Timeout settings _getUrlToString

If you can't read the Xml file containing your feed (because of a url timeout, or any other reason) then that's considered a fatal error. The solution is to point your channel to a feed path that is valid, exists, and can be read without timing out in 30 seconds or whatever interval you specify.
0 Kudos
matrixebiz
Roku Guru

Re: Brightscript Timeout settings _getUrlToString

Yes but hosting sites are not always reliable so I have added some multiple host redundancy for where the channel can read the xml from another server if one is down to future proof it. 
Like for example if I host the XML on pastebin and if pastebin ever decides to close then the channel tries the next server host for the XML, etc... I don't want to have to republish another package to change the XML path location.

result = parseXmlDocument ("http ......)
if result.count() < 1 then result = parseXmlDocument ("http ......)
0 Kudos
belltown
Roku Guru

Re: Brightscript Timeout settings _getUrlToString

Then I would suggest that you start by ensuring that an invalid/inaccessible feed is not handled as a fatal error.

In Parse.brs, change the readXml function to return Invalid if it cannot read and parse the Xml feed:


'
' Read an Xml document from a path (local file or remote url) and return an roXMLElement object
'
Function readXml (xmlPath As String) As Object

   ' Return an roXMLElement by parsing an Xml text file
   xml = CreateObject ("roXMLElement")

   ' Read the Xml document from either a local file or a remote url
   xmlString = _getPathToString (xmlPath, 5000)
   '_debug ("xmlString: " + xmlString)     ' un-comment to dump Xml file contents

   If xmlString <> ""
       If Not xml.Parse (xmlString)
           REM uiFatalError ("readXml", LINE_NUM, "Unable to parse Xml document: " + xmlPath)
           xml = Invalid
       End If
   Else
       REM uiFatalError ("readXml", LINE_NUM, "Unable to read Xml document: " + xmlPath)
      xml = Invalid
   End If

   Return xml

End Function

Next, it would probably be easier if parseXmlDocument returns Invalid for an invalid feed; it presently returns an empty associative array.
In Parse.brs change the following line in parseXmlDocument from:

contentItem = {}


to:

contentItem = Invalid


Then when you call parseXmlDocument in Main.brs, check for an Invalid return:


result = parseXmlDocument ("http ......)

if result = Invalid then result = parseXmlDocument ("http ......)
0 Kudos
matrixebiz
Roku Guru

Re: Brightscript Timeout settings _getUrlToString

Okay, thank you, I'll make the modification. A "Fatal Error' is a bad thing then? 🙂 
Does this cause unnecessary strain on the Roku or cause the channel to take even that much longer to load? 
0 Kudos
belltown
Roku Guru

Re: Brightscript Timeout settings _getUrlToString

"matrixebiz" wrote:
Okay, thank you, I'll make the modification. A "Fatal Error' is a bad thing then? 🙂 
Does this cause unnecessary strain on the Roku or cause the channel to take even that much longer to load? 

It just means that the channel can't do anything useful for the user, so it displays an error message then terminates. If your one and only xml feed url cannot be accessed and the channel's only function is to display the feed contents, then that would be considered a fatal error. If the channel can still perform other functions, e.g. access an alternate feed stream, that may not be a fatal error -- at least until attempts to access all alternate feeds fail.
0 Kudos
matrixebiz
Roku Guru

Re: Brightscript Timeout settings _getUrlToString

True but my "Last Resort" xml is a package contained XML so the channel still loads completely but just basically tells the user to contact me in this scenario so that I can upload a new fixed channel package. I'll then know something serious has gone wrong with all the XML server locations and to fix it ASAP plus let the users know that an update is coming with the fix;
if result.count() < 1 then result = parseXmlDocument ("pkg:/xml/xml.xml")
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.