When use blocking, StartAccepting() method of TSocketServer will not exit until its internal variable FAccepting is false. Calling StopAccepting outside this loop is useless. All sample applications, for example
https://github.com/graemeg/freepascal/blob/master/packages/fcl-base/examples/dsocksvr.pp, call StopAccepting inside OnConnect().
However, OnConnect() will be called only if there are data available. If there is no data available, then, stopAccepting may never be called. We can force to terminate application by sending SIGTERM/SIGINT signal, but that cause application is terminated immediately without opportunity to do some cleanup (closing open files, deleting temporary files etc).
How to gracefully shutdown TSocketServer?