From sgcWebSockets 2023.2.0 the HTTP/1 Client has been improved and supports SSE requests. Remember than SSE was already supported on Server components but not on client.
SSE (Server-Sent Events) is a web technology for efficiently receiving push notifications from a server to a client's browser. It's a standard that allows a web page to receive updates from a server in real-time without the need for constant polling. SSE is typically used to provide real-time updates for scenarios such as chat applications, sports scores, financial data, and others.
SSE operates over a single HTTP connection, and the browser automatically opens and maintains this connection. The server pushes updates to the client using this connection, which is held open for as long as the client is connected.
The TsgcHTTP1Client has a new method called GetSSE that sends an HTTP request to start an Event Stream between the server and client. Every time the client receives a new stream from the server, the event OnSSEMessage is called with the contents of the text message.
Find below a simple example.
oHTTP := TsgcHTTP1Client.Create(nil); oHTTP.OnSSEMessage := OnSSEMessageEvent; oHTTP.GetSSE('https://www.esegece.com/sse.php'); procedure OnSSEMessageEvent(Sender: TObject; const aMessage: string; var Cancel: Boolean); begin DoLog(aMessage); end;
The full source demo and the compiled project for windows can be downloaded below
When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.