You are not logged in.
Pages: 1
I created TWebSocketServer server and TWebSocketProtocolChat. When I connect it with JS it is fast.
But when I connect with below code it takes 5 second to upgrade.
var
ClientWS : THttpClientWebSockets;
lProto : TWebSocketProtocolEcho;
begin
lProto := TWebSocketProtocolEcho.Create('meow','');
lProto.OnIncomingFrame := EchoFrame;
ClientWS := THttpClientWebSockets.Create;
ClientWS.Open('127.0.0.1', '8383');
ClientWS.WebSocketsUpgrade('', '', false, [], lProto, '');
Offline
I accidentally changed the position of a line and the problem was solved. But why should this happen?
var
ClientWS : THttpClientWebSockets;
lProto : TWebSocketProtocolEcho;
begin
lProto := TWebSocketProtocolEcho.Create('meow','');
ClientWS := THttpClientWebSockets.Create;
ClientWS.Open('127.0.0.1', '12346');
ClientWS.WebSocketsUpgrade('', '', false, [], lProto, '');
lProto.OnIncomingFrame := EchoFrame; //this line moved here
Last edited by anouri (2025-04-20 06:12:46)
Offline
Is this bug or abnormal behaviour?
Last edited by anouri (2025-04-20 06:55:06)
Offline
I think there is issue in somewhere in mormot.
When lProto.OnIncomingFrame assigned before socket upgrade this function takes 5 seconds to finish
procedure TWebSocketProcess.WaitThreadStarted;
var
endtix: Int64;
begin
endtix := GetTickCount64 + 5000;
repeat
SleepHiRes(0);
until fProcessEnded or
(fState <> wpsCreate) or
(GetTickCount64 > endtix);
end;
Offline
EchoFrame method:
procedure TForm2.EchoFrame(Sender: TWebSocketProcess; const Frame: WebSocketFrame);
begin
case Frame.opcode of
focContinuation:
begin
TThread.Synchronize(nil, procedure
begin
Memo1.Lines.Add('connected');
end);
end;
end;
end;
Offline
TThread.Queue Solved the issue!
Offline
Pages: 1