TClientSocket Handling errors

TClientSocket Handling errors

Post by Davi » Wed, 16 Jun 2004 16:35:54

Hi all.
At this moment I'm working with Delphi 5 and the TClientSocket with some
applications and I would like to know if I'm doing fine the error handling
or someone has some advices to give me. I'm not sure if I must call the
close method of the socket with the errors...should I or automatically with
any error the socket is closed?

procedure TfrmPrincipal.csConexionError(Sender: TObject; Socket:
TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer);
ErrorCode := 0 ;
Socket.Close ; //Is this ok here, is dangerous?
bRetry := TRUE ; //this will make to try to reconnect in a
sort time

Thank you in advance.

TClientSocket Handling errors

Post by Eddie Zare » Sun, 20 Jun 2004 14:35:48

I haven't noticed any issues with closing a socket when an error
is found, though I always like to use winsock.shutdown() and
CloseSocket(Socket) as well.

Make sure you use Try...except blocks around any questionable
method calls, and always, without a doubt use a memory leak
checker like memproof.

-Eddie Z