[Lazarus] fpWeb and server-sent events

silvioprog silvioprog at gmail.com
Wed Jun 3 18:53:40 CEST 2020


Hi Luca.

I hope you are fine in the current world situation.

Some answers below to your questions 1 and 2.

On Wed, Jun 3, 2020 at 10:30 AM Luca Olivetti via lazarus <
lazarus at lists.lazarus-ide.org> wrote:

> Hello,
>
> I need to embed a simple web server in my application that
>
> 1) should server a couple of static files
> 2) send server-sent events


1) So, you can use any Pascal structure to serve files, even in a single
routine. BTW, if you want to resolve media types, you can use
fpmimetypes or BrookMediaTypes
<https://github.com/risoflora/brookframework/blob/expr/Source/BrookMediaTypes.pas>
.

2) As Michael explained, unfortunately, it is not supported in FCL-Web
(yet) . However, if you want a SSE structure out-of-the-box, you can
provide it using the Brook streaming, e.g.:

Minimal console example:
https://github.com/risoflora/brookframework/blob/expr/Examples/Console/FPC/httpsrvsse.lpr

Minimal LCL example:
https://github.com/risoflora/brookframework/blob/expr/Examples/LCL/HTTPServerSSE_frMain.pas

Both examples above declare a small HTML client showing how to consume it
via event source (EventSource). Optionally, you can use some async
structure (e.g.: TSpinWait.SpinUntil) to create a small polling to push/pop
the messages provided to the clients in a single long lived event.

HTH

--
Silvio Cl├ęcio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20200603/b852f2d4/attachment-0001.html>


More information about the lazarus mailing list