I can't stop my program using LazWebsockets lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- BlueIcaro · 2023-12-15 11:02 Hello, I'm trying to make a websocket client using https://github.com/Warfley/LazWebsockets. But I can't stop my program I wrote: Code: [Select]procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction); begin   try     FCommunicator.StopReceiveMessageThread;     begin       while FCommunicator.ReceiveMessageThreadRunning do //never leaves this loop       begin         Application.ProcessMessages;         Sleep(500);         Application.ProcessMessages;         FCommunicator.Close(True);       end;     end;   finally     FreeAndNil(FCommunicator);     CloseAction := caFree;   end; end;  But FCommunicator never stops receving messages. What is happening? I attach the project Thanks in advance /BlueIcaro ---------------------------------------------------------------------- Graham1 · 2023-12-16 04:10 I downloaded your project and tried it. I discovered you have fixed my problem (https://forum.lazarus.freepascal.org/index.php/topic,65537.0.html) with Access Violation errors as your websocketclient.pas and wsstream.pas files are different to the current Master version on Github. But now I also have the same problem as you. It looks like the ThreadRunning status, as well as the FCommunicator.Open flag, isn't getting updated so loops that check them never end. It's interesting that if I comment out all the lines like Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i while FCommunicator.xxxxx do sleep(nnn) then everything seems to work fine. It doesn't seem like a very safe solution though, so hopefully somebody else will find something. But I have also found another problem. If the IP address is set to one that doesn't exist then the Connect command waits for a long time, during which the program says 'Not responding', before finally coming back with a connection failed message. I use the code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    try    FCommunicator := Client.Connect(TSocketHandler.Create);   except      Memo1.Lines.Add('Connect failed');      exit;   end;  but it would be good to find out where the delay is happening and either reduce the timeout or add an Application.ProcessMessages. ---------------------------------------------------------------------- Warfley · 2023-12-18 12:54 As this is my library, I'll take a look at it, but sadly I won't have time for the rest of the year. Please create a GitHub issue and I'll try to fix it as soon as possible ---------------------------------------------------------------------- BlueIcaro · 2023-12-21 10:55 Hello @Graham1, I didn't modify that files, Only I downloaded the last version from github. @Warfley I'm going to open a issue. Thanks /BlueIcaro ---------------------------------------------------------------------- Warfley · 2023-12-21 15:38 As I said I do not have time to look at it, but if I remember correctly this may be a known problem that the receiver thread only check if it was halted between messages, so it will always wait for one more message. So try if the thread is actually continuing for more than one message. A simple workaround should be to send a ping message after the stop, as it should be answered with a pong, which results in the thread checking the stopped flag again and terminating afterwards. Need to fix that in the future by adding a timeout