0

roHttpServer setup Halts script after republishing presentation.

When republishing the same project to an XT-1144 player, my custom script halts right as I "server.SetPort(s.msgPort)". 

This server is setup in the "newCustomPlugin" function.  I notice via some debug print statements that this function reruns when I republish the exact same presentation. 

The server setup section looks like this:

s.server = CreateObject("roHttpSever", { port: 8082 })

s.server.SetPort(s.msgPort)

s.server.AddPostToString(...)

I assume the script is upset that another server is being setup on the same port. 

Is this "newCustomPlugin" function supposed to run again after a republish?

Is there a way to check that a server is already running at bootup?

2 comments

  • 0
    Avatar
    Sam

    Some further troubleshooting shows that, when the "roHttpSever" is recreated at the republishing, I get this error:

    [   56.882] BrightScript creation of roHttpServer failed:
    [   56.882]   Failed to create MHD daemon

  • 1
    Avatar
    Ken Campbell

    Sam,

    The usual pattern you'll see in Brightscript to address duplicate setup code is:

    if type(s.server) <> "roHttpServer" then
    s.server = CreateObject("roHttpSever", { port: 8082 })
    s.server.SetPort(s.msgPort)
    s.server.AddPostToString(...)

    Also a check to .GetFailureReason()

    None of this checks whether the port is already bound though. I don't see a built-in call to check this, but around about way of accomplishing this would be to make a GET request to the loopback using roUrlTransfer and checking the response code. Not elegant, but... 

    Ken

     

Please sign in to leave a comment.