I am trying to replicate the behavior of a server which responds to a http call with an ongoing JSON response and which via the assistance gained in this post, I have developed a client to consume that JSON data.
Within my server main module JSON is generated periodically using:
My current handler code is:
The initial JSON response is used by the client to confirm it has a connection to the server and then as the JSON is updated periodically in the main module, I require it to be "piped" to the handler response stream without requiring a new request.
But I am struggling to understand how I create a stream from the JSON (jg) and pipe it to the response (resp.Outputstream) each time the JSON is updated.
Examples of similar server functionality I can find on the Forum use websockets, however I want to replicate the other server functionality using a HTTP call and so I appreciate any pointers in the right direction.
Within my server main module JSON is generated periodically using:
B4X:
m = CreateMap("type":"clock","clock":gameClock,"shotClock":shotClock)
jg.Initialize(m)
My current handler code is:
B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
resp.ContentType = "application/json"
resp.Write($"{"type":"connection","status":"CONNECTED"}"$)
resp.Outputstream ??????????
End Sub
The initial JSON response is used by the client to confirm it has a connection to the server and then as the JSON is updated periodically in the main module, I require it to be "piped" to the handler response stream without requiring a new request.
But I am struggling to understand how I create a stream from the JSON (jg) and pipe it to the response (resp.Outputstream) each time the JSON is updated.
Examples of similar server functionality I can find on the Forum use websockets, however I want to replicate the other server functionality using a HTTP call and so I appreciate any pointers in the right direction.