Re: Limit bandwidth of clients with TCPServer

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

"Bahtiyar KARANLIK" <karanl…> wrote in message

> 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

Use this code instead:

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



In response to

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