If a client connection to a TCP server is gracefully disconnected from the client, the OnDisconnect event will be triggered. Your thread will also be marked terminated, so you should check for this in your loop.
However, for non-graceful disconnections, the TCP server will immediately error on the next read or write. You have wrapped your read and write in an empty try...except
block. Instead, you should handle the error and break out of the loop.
For Delphi 6, you should update your Indy components to the latest Indy v9 release.