Socket.Connected not made false after closing socket
Hi,
Sorry for giving the wrong subject line.
It is "Socket.Connected" not made false after closing socket
NOT socket.active.
I am restating my problem here.
In a project, I am using Delphi Winsock component for implementing
socket communication.
TClientSocket object is used to connect to a remote listening socket.
(The scope of the project is limited to the client implementation ,
and not the server. And I have no visibility of the server software).
As per a particular requirement, I need to forcibly close the client
socket. This is triggering the DisconnectEvent and the corresponding
event handler is getting called. But in the Disconnect event handler,
the socket is again closed only if socket.connected is true. The code
segment is as follows:
within a custom routine (where I am forcibly closing the client
socket)
-----------------------------------------------------------------------
TestFrm.TestClient.socket.close;
within Disconnect event handler
-------------------------------
if(Testfrm.TestClient.socket.connected)then
TestFrm.TestClient.socket.close;
But this always caused an exception 10038 (WSAENOTSOCK: An operation
was attempted on something that is not a socket), which means I am
trying to close a socket which is already closed. I am sure, this is
happening within the Disconnect event handler. i.e. socket.connected
is not false even after closing the socket from the custom routine.
I tried modifying the disconnect event handler as follows
if(Testfrm.TestClient.Active)then
TestFrm.TestClient.socket.close;
and this gave no error since "Active" becomes false on socket.close.
But, whether (Testfrm.TestClient.Active) serves the same purpose as
Testfrm.TestClient.socket.connected) at least in this requirement.
Thankyou.
Shehan