When using Tclientsocket and Tserversocket in Delphi for programming communication, When a client using Tclientsocket uses Tclientsocket.close to disconnect and exit the program, the server using Tserversocket will sometimes report ' asynchronous socket error 10053 ' This error, read the error description: Software caused connection abort. (Termination of connection due to software reasons). The reason for this is that it's very chicken, because you're still not sure where the problem is.
In fact, this error is very large because there is no client and the server connection is not disconnected directly to the tclientsocket to free, there are two solutions (in fact, is a kind of, but the solution is different, is to disconnect the connection)
One: Call TClientSocket.Socket.Close to disconnect the connection before calling Tclientsocket's close function, but there is another problem, that is, there is still no received full data, and the server will still be reported asynchronous Socket error 10053, so you can call TClientSocket.Socket.Close again before calling TClientSocket.Socket.ReceiveText to receive the data sent by the server fully
Second: Add the following code to the Onclienterror event on the server side:
Case ErrorCode of
10053:socket.close;
End
ErrorCode: = 0;
Disconnect the connection and set ErrorCode to 0, if not set, although the connection is broken, but the error code is still 10053, the window will still pop asynchronous socket error 10053.
DELPHI Newsletter Asynchronous socket error 10053 a workaround