Recent

Author Topic: Websockets Server/Client Implementation  (Read 15669 times)

senglit

  • Full Member
  • ***
  • Posts: 131
Re: Websockets Server/Client Implementation
« Reply #30 on: September 14, 2022, 04:40:05 am »
hi.

I have a websockets server(something like the demo "broacast server") started as a thread in my app. In the main thread I want to detect if the ws server works properly. If something wrong, I'd like to destroy the old ws server thread and start a new one.

In other job thread, I just do it by "feedding dog", to inc a counter defined as global.

How to do it with ws server? When the ws server thread is started up and socket.start is called the ws thread lost the control of socket and handler. I don't know where to add the "feed dog" clause.
I use Win10 + Lazarus 2.2.0 + FPC 3.2.2. All 64bit.

piola

  • Full Member
  • ***
  • Posts: 148
  • Lazarus 2.2, 64bit on Windows 8.1 x64
Re: Websockets Server/Client Implementation
« Reply #31 on: May 10, 2024, 05:23:12 pm »
Thank you for sharing this component.

Could you please allow registering custom handlers (prior to the check for a valid WebSocket request) so that TWebsocketServer can be used as an HTTP server, too?

Normally, this wouldn't be an issue, but WebSocket and HTTP share the same port.

Warfley

  • Hero Member
  • *****
  • Posts: 1849
Re: Websockets Server/Client Implementation
« Reply #32 on: May 13, 2024, 10:07:30 am »
A full HTTP implementation is out of scope for this library. I recommend instead to use a reverse proxy to dispatch requests to a common port (80/443) to applications running on different ports (e.g. one HTTP server one Websockets server)

piola

  • Full Member
  • ***
  • Posts: 148
  • Lazarus 2.2, 64bit on Windows 8.1 x64
Re: Websockets Server/Client Implementation
« Reply #33 on: May 13, 2024, 02:54:17 pm »
Thank you for your reply. I didn't want to suggest a full-featured HTTP server, it's clearly too much.

What's in my mind is more an event which gets fired before the internal websocket handshake occurs and which passes the complete request and allows to provide a response, together with a flag "IsHandled". If the flag is set, the internal websocket handshake can be skipped and the response can be directly sent. If the flag is unset, the internal handshake can continue just as it is currently happening.

 

TinyPortal © 2005-2018