Re: Limit bandwidth of clients with TCPServer

Giganews Newsgroups
Subject: Re: Limit bandwidth of clients with TCPServer
Posted by:  Remy Lebeau (TeamB) (no.spam@no.spam.com)
Date: Mon, 27 Feb 2006

"Bahtiyar KARANLIK" <karanl…@boun.edu.tr> wrote in message
news:5ADC095AE4EEE240karanl…@boun.edu.tr...

> is there something wrong with this code?

There are several things wrong with it:

1) you did not assign the throttle to the connection at all

2) you are not preserving the IOHandler that already exists prior to the
event being triggered

3) if you do not preserve the existing IOHandler, then you have to manually
hook up your new TIdIOHandleSocket instance to a valid socket, but you are
not doing that, so there is nothing for the IOHandler to read from or write
to.

Use this code instead:

    procedure TForm1.TCPServerConnect(AThread: TIdPeerThread);
    var
        Throttle: TIdIOHandlerThrottle;
    begin
        Throttle := TIdIOHandlerThrottle.Create(AThread.Connection);
        Throttle.ChainedHandler := AThread.Connection.IOHandler;
        Throttle.BytesPerSec := 50*1024;
        AThread.Connection.IOHandler := Throttle;
    end;

Gambit

Replies

In response to

Limit bandwidth of clients with TCPServer posted by Bahtiyar KARANLIK on Mon, 27 Feb 2006