Re: TIdInterceptThrottler problem

Giganews Newsgroups
Subject: Re: TIdInterceptThrottler problem
Posted by:  Remy Lebeau (TeamB) (no.spam@no.spam.com)
Date: Wed, 15 Dec 2004

"Michael J. Leaver" <spam@mjleaver.com> wrote in message
news:9173611F05B8E240spam@mjleaver.com...

> Hi, I'm using the TIdInterceptThrottler class (Indy 10) to try
> and limit the bandwidth used by my FTP client. However, it
> doesn't seem to be working.

Nor should it because you are not using it properly.

>      FTPClient.IOHandler.Intercept:=FFTPLimit;

That will not work.  You are assigning the throttle to the *command*
connection, not the *data* connection.  Keep in mind that the FTP protocol
uses multiple socket connections - one for sending commands, and each file
transfer has its own individual socket.

To do what you are asking, you need to assign the throttle to the *data*
connections that are used for each transfer.  You can use the
OnDataChannelCreate event for that, ie:

    procedure TForm1.IdFTP1DataChannelCreate(ASender: TObject; ADataChannel:
TIdTCPConnection);
    var
        LThrottle: TIdInterceptThrottler;
    begin
        LThrottle := TIdInterceptThrottler.Create(ADataChannel);
        ADataChannel.IOHandler.Intercept := LThrottle;
        LThrottle.BitsPerSec := 8192; // 1K
    end;

    procedure TForm1.IdFTP1DataChannelDestroy(ASender: TObject;
ADataChannel: TIdTCPConnection);
    begin
        with ADataChannel.IOHandler do begin
            Intercept.Free;
            Intercept := nil;
        end;
    end;

Gambit

Replies

In response to

TIdInterceptThrottler problem posted by Michael J. Leaver on Wed, 15 Dec 2004