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.
See if setMinimumTransferRate() does it for you.
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).
Thank you
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.
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 …)
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 ......)
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?
“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.
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”)
Hi Belltown, is the 5 second wait a min fixed time?;
xmlString = _getPathToString (xmlPath, 5000)
if I put 30 (Seconds), will it wait until the 30 seconds is up if no response or if a response is received before the 30 seconds will stop waiting then move on? Thx
“matrixebiz” wrote:
Hi Belltown, is the 5 second wait a min fixed time?;xmlString = _getPathToString (xmlPath, 5000)if I put 30 (Seconds), will it wait until the 30 seconds is up if no response or if a response is received before the 30 seconds will stop waiting then move on? Thx
It’s the maximum wait time when reading an external url (if the path is for a local package file, the timeout parameter does not apply). If a response is received before the timeout expires, the operation completes at that time, otherwise the operation will be cancelled when the timeout expires.
