Hello
Do you have any examples on how to use Sparkle HTTP server (http.sys) with Server Side Events (https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events).
I've been experimenting without success and would appreciate any advise .
Initially just trying a simple scenario where Sparkle server module would simply send a timestamp every 1 seconds.
I'm using a sample for client side that just logs data (https://github.com/mdn/dom-examples/blob/master/server-sent-events/index.html using my url) and static serving it from same sparkle server.
So far have this though as mentioned it it's not working - ProcessRequest is reached and run ok but client is not showing any data and similarly browser debug tools do not show any data in the EventStream
procedure TServerSideEventsModule.ProcessRequest(const C: THttpServerContext);
var
Writer: TStreamWriter;
begin
inherited;
C.Response.StatusCode := 200;
C.Response.Chunked := true;
C.Response.Headers.Clear;
C.Response.ContentType := 'text/event-stream';
C.Response.Headers.SetValue('Connection','keep-alive');
C.Response.Headers.SetValue('Cache-Control','no-cache');
Writer := TStreamWriter.Create(C.Response.Content, TEncoding.UTF8);
Writer.AutoFlush := true;
try
while not C.Response.Closed do
begin
Writer.Write('data: ' + DateTimeToStr(now) + '\n\n');
sleep(1000);
end;
finally
Writer.Free;
end;
end;
Thanks