Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
YungBlood
Level 7

[Solved] Http Async problems...

I'm having problems with http async. I had it working, then it broke. And I have been banging my head against the wall for weeks over this.


Function MainMenu(scr as object, m as integer, RegID as String) as integer
port = scr.GetPort()
cw = int(scr.getwidth()/2)
ch = int(scr.getheight()/2)
SButt = []
SButt[0] = CreateObject("roBitmap", "pkg:/images/gamemenu/buttons/selectplaynewgame.png")
SButt[1] = CreateObject("roBitmap", "pkg:/images/gamemenu/buttons/selectgamehelp.png")
UButt = []
UButt[0] = CreateObject("roBitmap", "pkg:/images/gamemenu/buttons/unselectplaynewgame.png")
UButt[1] = CreateObject("roBitmap", "pkg:/images/gamemenu/buttons/unselectgamehelp.png")
logo = CreateObject("roBitmap", "pkg:/images/gamemenu/memorymatchimg.png")
reg = CreateObject("roRegistry")
sec = CreateObject("roRegistrySection", "MemoryMatch")
fontreg = createobject("rofontregistry")
playerfile = CreateObject("roXMLElement")
players = "0"
url = "https://www.games4roku.com/gamesrv.php?key=" + RegID + "&cmd=PSTAT"
'NOTE: This is NOT the true url. However, everything works fine when I do it without async.
'

' x = AsyncHttpsGetToFile(url, "tmp:/players.xml", port)
x = AsyncHttpsGetToStr(url, port)
print x
' playerfile.Parse(HttpsGetToStr(url))
' players = playerfile.game@players
' print readasciifile("tmp:/players.xml")
head = fontreg.getdefaultfont(24, true, false)
top = 151
cx = cw + 110
rel = 1
white = &hffffffff
while true
BackGround(scr)
scr.drawtext("Players",cw+130,ch+50,white,head)
print type(players); " = "; players
scr.drawtext(players,cw+130,ch+80,white,head)
scr.drawobject(cw-280, ch-160, logo)
for y = 0 to 4
cy = (ch - top) + y*57
if(y = m) then
scr.drawobject(cx, cy, SButt[y])
else
scr.drawobject(cx, cy, UButt[y])
end if
end for
scr.swapbuffers()
msg = wait(1000, port)
if type(msg) = "roUniversalControlEvent" then
i = msg.GetInt()
if ((i = 2) and (rel = 1)) then
rel = 0
m = m - 1
if (m = -1) then exit while
else if ((i = 3) and (rel = 1)) then
rel = 0
if(m < 1) then m = m + 1
else if (i = 6) then
exit while
else if (i > 99) then
rel = 1
end if
else if type(msg) = "roUrlEvent" then
print "getint"; msg.getint()
print "getstring"; msg.getstring()
print "getfailurereason"; msg.getfailurereason()
print "getresponsecode"; msg.GetResponseCode()
print readasciifile("tmp:/players.xml")
playerfile.Parse(readasciifile("tmp:/players.xml"))
players = playerfile.game@players
' AsyncHttpsGetToFile(url, "tmp:/players.xml", port)
end if
end while
return m
End Function

Sub HttpsGetToFile(Url as String, File as string)
deletefile(File)
html = CreateObject("roUrlTransfer")
cert = "pk" + "g:/cert/ca.pem"
html.SetCertificatesFile(cert)
html.AddHeader("X-Roku-Reserved-Dev-Id", "")
html.InitClientCertificates()
html.SetUrl(Url)
html.getToFile(File)
End Sub

function HttpsGetToStr(Url as String)
html = CreateObject("roUrlTransfer")
cert = "pk" + "g:/cert/ca.pem"
html.SetCertificatesFile(cert)
html.AddHeader("X-Roku-Reserved-Dev-Id", "")
html.InitClientCertificates()
html.SetUrl(Url)
return html.getToString()
End function

function AsyncHttpsGetToStr(Url as String, port as object) as object
html = CreateObject("roUrlTransfer")
html.SetPort(port)
cert = "pk" + "g:/cert/ca.pem"
html.SetCertificatesFile(cert)
html.AddHeader("X-Roku-Reserved-Dev-Id", "")
html.InitClientCertificates()
html.SetUrl(Url)
return html.AsyncGetToString()
end function

function AsyncHttpsGetToFile(Url as String, file as string, port as object) as object
deletefile(file)
html = CreateObject("roUrlTransfer")
html.SetPort(port)
cert = "pk" + "g:/cert/ca.pem"
html.SetCertificatesFile(cert)
html.AddHeader("X-Roku-Reserved-Dev-Id", "")
html.InitClientCertificates()
html.SetUrl(Url)
return html.AsyncGetToFile(file)
end function


And here is what the output is:

true
String = 0
getint 1
getstring
getfailurereasonCancelled
getresponsecode-10001

Invalid = invalid


I thought it was a problem with the latest beta, but it failed on my box that isn't on beta code.
YungBlood

Bringing more fun to Roku!
0 Kudos
1 Reply
YungBlood
Level 7

Re: [Solved] Http Async problems...

All I can say is *Doh*.... I had to create the roUrlTransfer object outside of the function...


Function MainMenu(scr as object, m as integer, RegID as String) as integer
http = CreateObject("roUrlTransfer")
port = scr.GetPort()
url = "https://www.games4roku.com/gamesrv.php?key=" + RegID + "&cmd=PSTAT"
AsyncHttpsGetToStr(url, http, port)
message = wait(0,port)
print message.GetString()
...
End Function

function AsyncHttpsGetToStr(Url as String, port as object) as object
html = CreateObject("roUrlTransfer")
html.SetPort(port)
html.SetCertificatesFile("common:/certs/ca-bundle.crt")
html.AddHeader("X-Roku-Reserved-Dev-Id", "")
html.InitClientCertificates()
html.SetUrl(Url)
return html.AsyncGetToString()
end function
YungBlood

Bringing more fun to Roku!
0 Kudos