Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2021-09

FCL-Web updates/extensions

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt

Hello,

Thanks to the efforts of Ondrej Pokorny and some sponsored work by the FPC/Lazarus foundation, FCL-Web has received some updates:

- Improvements in fcl-net, basically a Select() call has been added to the socket stream, on all platforms that support this.

- Possibility to keep connections open in the HTTP Server (keep-alive).

- A HTTP client connection pool, for parallel downloading.

- HTTP Client Downloads can now be canceled.

- New threading model for the FPC HTTP server:
- No threading
- One thread per request/connection
- Thread pool, distributing requests over available threads.

- The thread pool functionality is in a separate unit, available for other things as well...

- Interceptors in the HTTP router:
In the HTTP router you can now register interceptors. These will be run before/after the request is dispatched to the correct handler.

Interceptors can cancel further handling of a request: This allows you to implement e.g. authentication, logging etc. in an orthogonal manner to normal request handling.

- The FPC HTTP server can now handle Connection: upgrade using registered upgrade handlers. This can be used for websocket (see below) and later HTTP/2 handling.

- FPC has now native support for the websocket protocol: both client and server are supported. Native chat client/server demos are included, and a pas2js client for use in the browser is also available. (SSL support is there but still needs testing)

- The websocket protocol support can be attached to the HTTP server. That means you can initiate a websocket connection on the same port as the HTTP server is listening; the HTTP server will hand off the connection to the websocket server using the upgrade mechanism. A server demo is included as well.

Attached a small screenshot of the websocket-based chat program in pas2js.

Enjoy,

Michael.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: chatbox.png
Type: image/png
Size: 39878 bytes
Desc:
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210901/710131f9/attachment-0001.png>

Reply by email

Luca Olivetti
to Michael Van Canneyt

El 1/9/21 a les 13:06, Michael Van Canneyt via lazarus ha escrit:

Show quoted text 7 lines
- The websocket protocol support can be attached to the HTTP server. That   means you can initiate a websocket connection on the same port as the HTTP   server is listening; the HTTP server will hand off the connection to the   websocket server using the upgrade mechanism. A server demo is included as well.

Having not seen the implementation, my questions are:

1) existing code will still work unmodified?
2) specifically the hack for server-sent events I mentioned here https://lists.lazarus-ide.org/pipermail/lazarus/2020-June/238089.html will still work?

1) I suppose is a given ;-), 2) I ask because you only mentioned websockets and not server-sent events.

Bye

Luca Olivetti Wetron Automation Technology http://www.wetron.es/ Tel. +34 93 5883004 (Ext.3010) Fax +34 93 5883007

Reply by email

Michael Van Canneyt
to Luca Olivetti
Luca Olivetti wrote 12 lines
El 1/9/21 a les 13:06, Michael Van Canneyt via lazarus ha escrit: > > - The websocket protocol support can be attached to the HTTP server. That >   means you can initiate a websocket connection on the same port as the > HTTP >   server is listening; the HTTP server will hand off the connection to the >   websocket server using the upgrade mechanism. A server demo is > included as well. Having not seen the implementation, my questions are: 1) existing code will still work unmodified?

Yes.

2) specifically the hack for server-sent events I mentioned here https://lists.lazarus-ide.org/pipermail/lazarus/2020-June/238089.html will still work?

The pastebin link is down ?

1) I suppose is a given ;-), 2) I ask because you only mentioned websockets and not server-sent events.

Server events are normally done using HTTP/2, and this is planned.

I can't promise your code will still run, but since the server was modified to keep connections alive indefinitely, I suppose that you should now be able to handle server events even easier with the upgrade mechanism;

It's just a matter of deciding to 'upgrade' depending on the URL & headers in the initial request. In case you try to take a shot at it and you need help implementing it, let me know...

Michael.

Reply by email

Luca Olivetti
to Michael Van Canneyt

El 1/9/21 a les 17:14, Michael Van Canneyt via lazarus ha escrit:

Show quoted text 5 lines
> 2) specifically the hack for server-sent events I mentioned here > https://lists.lazarus-ide.org/pipermail/lazarus/2020-June/238089.html > will still work? The pastebin link is down ?

it's still there but it requires a login, anyway, I copied it here

https://pastebin.com/gyqS83Nt

Show quoted text 6 lines
> > 1) I suppose is a given ;-), 2) I ask because you only mentioned > websockets and not server-sent events. Server events are normally done using HTTP/2, and this is planned.

well, I'm successfully using it over http 1.1 (I suppose that's the only protocol currently supported by fpWeb)

Show quoted text 5 lines
I can't promise your code will still run, but since the server was modified to keep connections alive indefinitely, I suppose that you should now be able to handle server events even easier with the upgrade mechanism;

It'd be enough for it to continue working as it is....

It's just a matter of deciding to 'upgrade' depending on the URL & headers in the initial request. In case you try to take a shot at it and you need help implementing it, let me know...

...when I have to modify the project using the above hack, though this could happen next month, next year or never. In that case I could try to adapt the code to the new paradigm but, as I said, I'd prefer it to continue working as it is ;-)
(most probably because the http server part won't be the part I'll need to modify).

Bye

Luca Olivetti Wetron Automation Technology http://www.wetron.es/ Tel. +34 93 5883004 (Ext.3010) Fax +34 93 5883007

Reply by email