08-13-2026, 05:14 AM
I think that the reason for getting two threads created might be that the http connection and websocket context were not separated.
Remy supplied a change of code (addition) in the TWebSocketServer.Create constructor:
FWebSocketServer.OnWebSocketExecute := DoServerWebSocketExecute;
Whereas before I had been handling everything in the DoServerExecute procedure.
FWebSocketServer.OnWebSocketExecute := Self.DoServerExecute;
FWebSocketServer.OnExecute := DoServerExecute;
FWebSocketServer.OnConnect := DoServerConnect;
FWebSocketServer.OnDisconnect := DoServerDisconnect;
Now trying suggested code change:
Code:
constructor TMyWebSocketManager.Create;
begin
inherited Create(nil);
FWebSocketServer := TWebSocketServer.Create;
// Initialize the thread lock container
FSessionLock := TCriticalSection.Create;
// Initialize the dictionary container to hold your session memory references
FSessionMap := TDictionary<string, TMyClientSession>.Create;
FWebSocketServer.ContextClass := TMyClientContext;
FWebSocketServer.OnWebSocketExecute := DoServerWebSocketExecute;
FWebSocketServer.OnConnect := DoServerConnect;
FWebSocketServer.OnDisconnect := DoServerDisconnect;
FCommandQueue := TThreadedQueue<TWSCommand>.Create(1024, 0, 0);
LogAddMsg('Server created, waiting for activation');
end;
My question now is whether FWebSocketServer.OnExecute := DoServerExecute; is not required anymore or what should it be used for? What is the difference between FWebSocketServer.OnExecute and FWebSocketServer.OnWebSocketExecute ?
Remy supplied a change of code (addition) in the TWebSocketServer.Create constructor:
FWebSocketServer.OnWebSocketExecute := DoServerWebSocketExecute;
Whereas before I had been handling everything in the DoServerExecute procedure.
FWebSocketServer.OnWebSocketExecute := Self.DoServerExecute;
FWebSocketServer.OnExecute := DoServerExecute;
FWebSocketServer.OnConnect := DoServerConnect;
FWebSocketServer.OnDisconnect := DoServerDisconnect;
Now trying suggested code change:
Code:
constructor TMyWebSocketManager.Create;
begin
inherited Create(nil);
FWebSocketServer := TWebSocketServer.Create;
// Initialize the thread lock container
FSessionLock := TCriticalSection.Create;
// Initialize the dictionary container to hold your session memory references
FSessionMap := TDictionary<string, TMyClientSession>.Create;
FWebSocketServer.ContextClass := TMyClientContext;
FWebSocketServer.OnWebSocketExecute := DoServerWebSocketExecute;
FWebSocketServer.OnConnect := DoServerConnect;
FWebSocketServer.OnDisconnect := DoServerDisconnect;
FCommandQueue := TThreadedQueue<TWSCommand>.Create(1024, 0, 0);
LogAddMsg('Server created, waiting for activation');
end;
My question now is whether FWebSocketServer.OnExecute := DoServerExecute; is not required anymore or what should it be used for? What is the difference between FWebSocketServer.OnExecute and FWebSocketServer.OnWebSocketExecute ?

