matrixebiz
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2016
02:45 PM
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.
_getUrlToString. roUrlEvent. Int: 1. ResponseCode: -28. FailureReason: Connection timed out after 30001 milliseconds.
11 REPLIES 11
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2016
03:36 PM
Re: Brightscript Timeout settings _getUrlToString
See if setMinimumTransferRate() does it for you.
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2016
04:07 PM
Re: Brightscript Timeout settings _getUrlToString
In Parse.brs (line 48) change:
to:
where the 2nd parameter is the maximum number of milliseconds you want to wait for (5000ms = 5 seconds).
' 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).
matrixebiz
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2016
04:10 PM
Re: Brightscript Timeout settings _getUrlToString
Thank you
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2016
04:23 PM
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.
matrixebiz
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2016
04:43 PM
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 ......)
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 ......)
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2016
05:19 PM
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:
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:
to:
Then when you call parseXmlDocument in Main.brs, check for an Invalid return:
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 ......)
matrixebiz
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2016
05:31 PM
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?
Does this cause unnecessary strain on the Roku or cause the channel to take even that much longer to load?
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2016
05:40 PM
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.
matrixebiz
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2016
05:51 PM
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")
if result.count() < 1 then result = parseXmlDocument ("pkg:/xml/xml.xml")