(08-02-2026, 02:17 AM)hamstring Wrote: It has always been my understanding that the original thread would be retained after the upgrade and re-used for the handling of the websocket communications as well.
Only if you code your event handler to work that way. TIdCustomTCPServer doesn't care what you do with the socket. Its Execute event just loops until the connection is closed. You define what the event does on each iteration. If you were using TId(Custom)HTTPServer, its Execute logic reads an HTTP request and sends an HTTP response per iteration. You would service the websocket in the event handler after sending the upgrade response, so flow doesn't return to the server for the next request.
(08-02-2026, 02:17 AM)hamstring Wrote: I don't know why a new thread is created after the upgrade
What makes you think a new thread is being created? Where are you seeing it, exactly?
It's possible that the client is using one connection+thread to retrieve the HTML page, and then another connection+thread to connect the websocket. An upgrade starts as an HTTP request, and there is no requirement in HTTP that multiple requests use the same connection. Is your HTTP client/server using keep-alives between requests?
By default, Indy uses 1 thread per connection. You can opt-in to pool threads for reuse across connections.
HTTP can use multiple connections across requests, but Websocket does not. Once an HTTP connection is upgraded to Websocket, the connection is used only for that Websocket until the connection is closed.
(08-02-2026, 02:17 AM)hamstring Wrote: perhaps the initial HTTP thread creation is not aware that it has to handle the websocket following the upgrade.
Indy has no concept of websockets. That is just extra logic you build into your HTTP request handler.
(08-02-2026, 02:17 AM)hamstring Wrote: My big problem is that I am new to Indy and lacking the knowledge of what is happening at backstage.
It would be useful if you could show the actual code you are struggling with. Don't need the whole project, just the HTTP/upgrade portion.