' Ported from https://sourceforge.net/p/rokusdkexamples/code/HEAD/tree/trunk/rokusdkexamples-code/web_server/

' function Main(args as dynamic)
'     m.msgPort = CreateObject("roMessagePort")

'     settings = new RokuYoutube.Http.HttpSettings(m.msgPort)

'     ' Root at www to get http://192.168.1.107:8888/index.html
'     settings.WwwRoot = "pkg:/www"

'     print `Using settings: ${settings}`

'     server = new RokuYoutube.Http.HttpServer(settings)

'     m.running = true
'     timeout = validint(settings.Timeout)
'     timer = CreateObject("roTimespan")
'     update = true

'     while (m.running)
'         if update
'             timer.mark()
'             PrintServerStatus(server)
'             update = false
'         end if
'         server.PreWait()
'         msg = wait(timeout, settings.MessagePort)
'         tm = type(msg)
'         if tm="roSocketEvent" or msg=invalid
'             server.PostWait()
'         end if
'         if timer.totalSeconds()>=5 then update = true
'     end while

'     server.Close()
' end function

' function PrintServerStatus(server as HttpServer)
'     print("-------")
'     print(server.stats())
'     connections = server.connections
'     count=0
'     for each connID in connections
'         conn = connections[connID]
'         print (`  - Client: ${conn.client}; Total sent: ${conn.total_sent}; ID: ${conn.id}`)
'         count++
'     end for
'     if count = 0
'         print("  No active connections")
'     end if
'     print("-------")
' end function