Re: Already connected

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

"sunrizer" <sunriz…@ukr.net> wrote in message
news:C08F42527848E340sunriz…@ukr.net...

> 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.

    try
        Smtp.Connect;
    except
        on E: EIdException do begin
            tmp := E.Message;
    end;

Gambit

Replies

In response to

Already connected posted by sunrizer on Wed, 13 Feb 2008