Re: Already connected

Giganews Newsgroups
Subject: Re: Already connected
Posted by:  Remy Lebeau \(Indy Team\) (
Date: Wed, 13 Feb 2008

"sunrizer" <sunriz…> wrote in message

> When I try to connect to the SMTP-server - it raises exception
> EidAlreadyConnected, previously I disconnect. There is a sample code:

You did not say which version of Indy you are using, but I suspect you are
using an older version that does not clear the connection's InputBuffer
automatically.  Indy treats a connection as being connected, even if it
really isn't, if there is unread data in the InputBuffer.

> try
>  Smtp.Connect;
> except on E: EIdException do begin
>  if (SmtpSender.Connected) then begin
>  try
>      SmtpSender.Disconnect(False);
>    except on E: EIdException do
>      tmp:=E.Message;
>    end;
>  end;
>  end;

That is redundant.  Connect() already calls Disconnect() internally if an
exception is raised.

        on E: EIdException do begin
            tmp := E.Message;



In response to

Already connected posted by sunrizer on Wed, 13 Feb 2008