2

I'm getting the issue(Execution TimeOut) with the Task node. I created one Timer in the Scene node for Continuous Execute Function Here I Tried With Continuous Response Update With Task node and After It used in Scene Node.

'Timer

m.Update = m.top.findNode("SampleID")
m.Update .observeField("fire", "UpdateSample")
m.global.responseurl = m.urlassign
m.Update.control = "RUN"

'My Function

function UpdateSample()
    m.Sample= CreateObject("roSGNode", "SampleTask")
        m.Sample.control = "RUN"
        ?"m.global.responsecontent : " m.global.responsecontent 
end function 

'My Task Node

sub init()
?"Start Init()"
    m.DowndloadResponse = CreateObject("roUrlTransfer")
    m.DowndloadResponse.SetUrl(m.global.responseurl)
    m.Cont= m.DowndloadResponse.GetToString()
    m.global.responsecontent = m.Cont
    ?"m.global.responsecontent : " m.global.responsecontent 
?"End Init()"
end sub

Here, Not getting every time DowndloadResponse.GetToString() "Execution TimeOut". Sometimes It Gives the Error. I tried with m.top.functionname. But It's Execution at once. I also Tried with Timer Set in Task Node. But No luck. I required It's multiple. I don't know Which one is a good way to implement this. Does Anyone any idea how do solve this problem?

1 Answers1

1

You're using the Task node incorrectly, you have to absolutely use functionName.

I would also recommend using asyncGetToString() since it'll let you read response codes. You also have to set and initialize certificates for HTTPS requests (the Roku standard cert bundle should do).

You should have something like this inside your task thread function:

request = CreateObject("roUrlTransfer")
request.retainBodyOnError(true)
request.setUrl(url)

' Needed for HTTPS requests
request.setCertificatesFile("common:/certs/ca-bundle.crt")
request.initClientCertificates()

port = CreateObject("roMessagePort")
request.setPort(port)

timeout = 0 ' Force a timeout (0 equals "indefinite", or until Roku decides to terminate the request... ~60s)
event = wait(timeout, port)

if event <> invalid and type(event) = "roUrlEvent"
    ?"event.getString() "event.getString()
    ?"event.getResponseCode() "event.getResponseCode()
    ?"event.getFailureReason() "event.getFailureReason()
end if

' Ensure the request does not continue to run after the forced timeout is hit
' (Only necessary if you set a non-zero timeout)
request.asyncCancel()
Alejandro Cotilla
  • 2,501
  • 1
  • 20
  • 35
  • Hello thank you for your great reply. I use m.top.functionname = "myfunctionname" in init(). And put code inside of myfunctionname It work for continuous request? – Nikunj Chaklasiya Apr 09 '20 at 18:13
  • @NikunjChaklasiya not sure what you mean by "continuous request"? – Alejandro Cotilla Apr 09 '20 at 20:29
  • My response change every second from server. so I required to send request in every second by roku. But using my code i tried with m.top.functioname it only run in single time not multiple times. I required to using same API call infinite. – Nikunj Chaklasiya Apr 10 '20 at 03:14
  • @NikunjChaklasiya You can keep a `while` loop running in the task thread to achieve what you're trying to do. – Alejandro Cotilla Apr 14 '20 at 19:39