@Erel I have taken on board your pointer to use Wait For in the server handler, but I'm still encountering a "road block".
As indicated above, the code to generate the JSON as the scoreboard clock data updates in Main is:
[CODE lang="b4x" title="Main"]Sub clk_Tick
m = CreateMap("type":"clock","clock":gameClock,"shotClock":shotClock)
jg.Initialize(m)
update = True
Log("clk_Tick : " & jg.ToString)
End Sub[/CODE]
I have added a timer to the handler code so I can use the Timer_Tick event in conjunction with Wait For (because I can't see another suitable event):
[CODE lang="b4x" title="Handler"]Sub Handle(req As ServletRequest, resp As ServletResponse)
resp.ContentType = "application/json"
resp.Write($"{"type":"connection","status":"CONNECTED"}"$)
StartTimer
Do While True
If Main.update = True Then
resp.Write(Main.jg.ToString)
Log("Writing . . . " & Main.jg.ToString)
Main.update = False
End If
Log("Waiting . . .")
Wait For trg_Tick
Log("Looping . . .")
Loop
StartMessageLoop
End Sub
Sub StartTimer
Public trg As Timer
trg.Initialize("trg", 300)
trg.enabled = True
Log("Timer started . . ")
End Sub
Sub trg_Tick
Log("trg_Tick")
End Sub[/CODE]
However while as per the log below, the timer (trg) is started, the relevant timer event (trg_Tick) does not appear to fire and so the loop just sits waiting for it:[CODE lang="b4x" title="Log"]Server started
Update DuckDNS: OK
clk_Tick : {"shotClock":"24","clock":"9:56","type":"clock"}
clk_Tick : {"shotClock":"23","clock":"9:55","type":"clock"}
clk_Tick : {"shotClock":"22","clock":"9:54","type":"clock"}
clk_Tick : {"shotClock":"21","clock":"9:53","type":"clock"}
clk_Tick : {"shotClock":"20","clock":"9:52","type":"clock"}
clk_Tick : {"shotClock":"19","clock":"9:51","type":"clock"}
clk_Tick : {"shotClock":"18","clock":"9:50","type":"clock"}
clk_Tick : {"shotClock":"17","clock":"9:49","type":"clock"}
clk_Tick : {"shotClock":"16","clock":"9:48","type":"clock"}
Request received by handler
Timer started . .
Writing . . . {"shotClock":"16","clock":"9:48","type":"clock"}
Waiting . . .
clk_Tick : {"shotClock":"15","clock":"9:47","type":"clock"}
clk_Tick : {"shotClock":"14","clock":"9:46","type":"clock"}
clk_Tick : {"shotClock":"13","clock":"9:45","type":"clock"}
clk_Tick : {"shotClock":"12","clock":"9:44","type":"clock"}
clk_Tick : {"shotClock":"11","clock":"9:43","type":"clock"}
clk_Tick : {"shotClock":"10","clock":"9:42","type":"clock"}
clk_Tick : {"shotClock":"9","clock":"9:41","type":"clock"}
clk_Tick : {"shotClock":"8","clock":"9:40","type":"clock"}
clk_Tick : {"shotClock":"7","clock":"9:39","type":"clock"}[/CODE]
Moving the "Do while True" loop to a separate sub and calling that from the handle sub results in different issue:[CODE lang="b4x" title="Handler"]Sub WriteOutput(resp As ServletResponse)
Do While True
If Main.update = True Then
resp.Write(Main.jg.ToString)
Log("Writing . . . " & Main.jg.ToString)
Main.update = False
End If
Log("Waiting . . .")
Wait For trg_Tick
Log("Looping . . .")
Loop
End Sub[/CODE]
As per the log below, it seems timer event (trg_Tick) is firing because we see "Waiting . . ." and then "Looping . . .", but while it says "Writing . . . {"shotClock":"14","clock":"9:46","type":"clock"}", that is not actually sent as a response, I assume because the sub is not exited.[CODE lang="b4x" title="Log"]Server started
Update DuckDNS: OK
clk_Tick : {"shotClock":"24","clock":"9:56","type":"clock"}
clk_Tick : {"shotClock":"23","clock":"9:55","type":"clock"}
clk_Tick : {"shotClock":"22","clock":"9:54","type":"clock"}
clk_Tick : {"shotClock":"21","clock":"9:53","type":"clock"}
clk_Tick : {"shotClock":"20","clock":"9:52","type":"clock"}
clk_Tick : {"shotClock":"19","clock":"9:51","type":"clock"}
clk_Tick : {"shotClock":"18","clock":"9:50","type":"clock"}
clk_Tick : {"shotClock":"17","clock":"9:49","type":"clock"}
clk_Tick : {"shotClock":"16","clock":"9:48","type":"clock"}
clk_Tick : {"shotClock":"15","clock":"9:47","type":"clock"}
clk_Tick : {"shotClock":"14","clock":"9:46","type":"clock"}
Request received by handler
Timer started . .
Writing . . . {"shotClock":"14","clock":"9:46","type":"clock"}
Waiting . . .
Looping . . .
Waiting . . .
clk_Tick : {"shotClock":"13","clock":"9:45","type":"clock"}
Looping . . .
Writing . . . {"shotClock":"13","clock":"9:45","type":"clock"}
Waiting . . .
Looping . . .
Waiting . . .
Looping . . .
Waiting . . .
clk_Tick : {"shotClock":"12","clock":"9:44","type":"clock"}
Looping . . .
Writing . . . {"shotClock":"12","clock":"9:44","type":"clock"}
Waiting . . .
Looping . . .
Waiting . . .
Looping . . .
Waiting . . .
clk_Tick : {"shotClock":"11","clock":"9:43","type":"clock"}
Looping . . .
Writing . . . {"shotClock":"11","clock":"9:43","type":"clock"}
Waiting . . .
Looping . . .
Waiting . . .
Looping . . .[/CODE]
Often when I reach these "road blocks" I find I'm using an incorrect method to achieve the desired functionality and perhaps that's again the case, but any assistance will be gratefully received.