The problem is that you are reusing the same TIdSimpleServer
object each time.
After the first disconnect, the same IOHandler
is reused for the next connection, but the IOHandler.ClosedGracefully
property remains true from the earlier connection becaue it is not being reset each time. The ClosedGracefully
property is reset only by the IOHander.Open()
method, which TIdSimpleServer
calls only when it creates a new IOHandler
. Disconnect()
does not free the IOHandler
, but it does call IOHandler.Close()
.
The missing call to Open()
on subsequent connections looks like a bug to me, so I have checked in a fix for it to Indy's SVN (rev 5103).
You can either upgrade to the latest SVN release, or else you will have to destroy the TIdSimpleServer.IOHandler
(or the TIdSimpleServer
itself) in between each connection.