Check for 404 error

Hello, is there a simple Brightscript 2-3 lines of code that I can use to check if a url is alive or not and if it gives a 404 error then return the 404 error so I can try another url? Thank you

Is this a hard question? All I need to do is check and see if the url is good (valid) or bad (404) in my RSG VideoScene.brs file.
Can I use some of this Function?

Function check(thisurl) as string
request = CreateObject("roUrlTransfer")
port = CreateObject("roMessagePort")
request.SetMessagePort(port)
request.SetUrl(thisurl)
if (request.AsyncGetToString())
while (true)
msg = wait(0, port)
if (type(msg) = "roUrlEvent")
code = msg.GetResponseCode()
if (code = 200)
print"good"
return "good"

elseif (code =400 or code=404)
print("image not found")
return "bad"
else
print"error"; code
return "generic bad code"

endif
else if (event = invalid)
request.AsyncCancel()
endif
end while
endif
return invalid
End Function 

Anyone have the correct simplified code for me?

Anyone?

not tested

Function Ping()
 
 UT = CreateObject( "roUrlTransfer" )
 port = CreateObject("roMessagePort")
 UT.SetPort(port)
 UT.SetUrl("URL HERE")
 UT.AsyncHead()
 event = wait (0, port)
 if type(event) = "roUrlEvent"
 if event.GetResponseCode() = 200 
 'do something'
 else if event.GetResponseCode() = 404
 'do something else'
 end if
end if

End Function

Hello, thanks for responding but I get this error;

BRIGHTSCRIPT: ERROR: roUrlTransfer: creating MAIN|TASK-only component failed on RENDER
‘Dot’ Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in pkg:/components/VideoScene.brs(36)
036: UT.SetPort(port)

This is a RSG channel - https://github.com/rokudev/videoplayer-channel

The function works, putting it in the right place is up to you. I don’t know RSG but it looks like it’s in the wrong thread.

Anyone know the Scene Graph coding? and where in the VideoScene.brs file I can put a URL 404 check function?
https://github.com/rokudev/videoplayer-channel

Have you tried putting it in the UriHandler Task?

I think I did try that file (UriHandler.brs) but the actual url gets converted into a uri before it hits this file so that file confused me on where to put the url check.

Anyone else know where to put the URL check code into VideoScene.brs properly?

I tied to use Print Eval(http://www.server.net/badfile.xml) to get a 200 or 404 return but all it printed was <Component: roList> = ( <Component: roAssociativeArray> ) Is that not the right syntax for Eval?[/font][/size][/color]