Synapse: CanRead in terminated thread lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- fpcoder · 2014-07-12 17:53 EDIT: Why does CanRead become true when the server thread terminates? It causes the program to go on and create a new ClientThread even when Terminated is true. After understanding that this happened, I worked around it by changing: Code: [Select]  if CanRead(1000) then to this: Code: [Select]  if CanRead(1000) and (not Terminated) then But is that good? Shouldnt something like that be in one of the demos if so? Or I have not understood how it should be done? Code: [Select]procedure TMyServer.Execute; var   ClientSock: TSocket;   aClientThread: TClientThread; begin   with Sock do   begin     CreateSocket;  // auto-created by Synapse if not done manually}     SetLinger(True, 10000);     Bind('0.0.0.0','7070');     Listen;     if LastError = 0 then Log('Server is Online');     repeat       if Terminated then       begin         if Assigned(aClientThread) then aClientThread.Terminate;         Break;       end;       if CanRead(1000) and (not Terminated) then  //Neglect CanRead if serverthread is terminated!       begin         Log('Server: Someone connected');         ClientSock := Accept;         if LastError = 0 then         begin           aClientThread:= TClientThread.Create(ClientSock);           aClientThread.OnLog:= Self.OnLog; //Enable logging to main form           aClientThread.Start;         end;       end;     until False;   end; end; @Hinst: thanx for you advice, I'll look into your code. Most of all I'd like to learn this stuff and do it myself. I'm trying with Synapse because that seems more lightweight, but if the lack of documentation becomes too much, then I guess Indy will substitute. Indy has lots of examples and info floating around. ---------------------------------------------------------------------- hinst · 2014-07-12 19:59 Not sure if it will help. Well, it depends on what u desire https://bitbucket.org/hinst/paslog PasLog/Src/NetLogWrite.lpr : demonstrates how to emit log messages PasLog/SrcNLR/NetLogRead.lpi : log viewer, provide fpGUI to compile PasLog/H1N3_PasLog.lpk,  PasLog/H1N3_PasLogNet.lpk : packages for Lazarus You may either use it or look at it, it works more or less, it sends log over TCP, viewer application receives messages, has tabs and filters and some other useful (well, at least for me) things it's up to you whether u want ur own solution or try to use this, it surely works, but it might be not so easy to deploy, although nothing special here, just download some libraries and then some and then compile it i don't know i've been working on it for about 5 months and used it in my prjcts well, anyway, with my help it shouldn't take more than 1 hour to deploy it I think