03-13-2024, 10:28 PM
(03-12-2024, 04:44 PM)rlebeau Wrote:(03-12-2024, 04:08 PM)Ahmed Sayed Wrote: I know that all of these classes inherit from TIdTCPClientCustom so there must be a common way to close them on that class level.
Simply call their Disconnect() method, which is inherited from TIdTCPConnection. It should not raise an exception, but if it does, just catch it.
In the case of TIdFTP and various other higher-level protocol components, Disconnect() will send a goodbye message to the peer before shutting down the connection. If you don't want to send that message, Disconnect() has an optional ANotifyPeer parameter that you can set to false.
(03-12-2024, 04:08 PM)Ahmed Sayed Wrote: I need this to make sure that there are no resources like sockets, or connections that are still open before the client gets destroyed.
You don't need to worry about that. The client's destructor will shutdown the connection and close the socket if it is still active.
The way I know it is that to close the connection from the client side, I have to do something similar to this:
Code:
IdHTTP->IOHandler->WriteBufferClear();
IdHTTP->IOHandler->InputBuffer->Clear();
IdHTTP->IOHandler->Close();
IdHTTP->DisconnectNotifyPeer();
