Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Feb : Re: IdTCPServer and IdIOHandlerThrottle

www.cryer.info
Managed Newsgroup Archive

Re: IdTCPServer and IdIOHandlerThrottle

Subject:Re: IdTCPServer and IdIOHandlerThrottle
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Tue, 20 Feb 2007 11:59:56

"Beto Neto" <nospam@domain.com> wrote in message
news:45d5cdcd@newsgroups.borland.com...

> I'm trying to set on IdTCPServer1.OnConnect:
>
>     IdIOHandlerThrottle1.BytesPerSec := 31457280; //  30kb/s
>     AThread.Connection.IOHandler := IdIOHandlerThrottle1;
>
> After set it, the server close the client connection...
> Why ?!

You did not hook up the original IOHandler to the other side of the
Throttler, so it had nothing to do when data was being read from, or
written to, the socket.  So the server thinks the connection has been
closed.

Try this instead (untested):

    type
        TIdTCPConnectionAccess = class(TIdTCPConnection);

    procedure TForm1.IdTCPServer1Connect(AThread: TIdPeerThread);
    var
        Throttle: TIdIOHandlerThrottle;
    begin
        Throttle := TIdIOHandlerThrottle.Create(AThread.Connection);
        Throttle.BytesPerSec := 31457280;

        { TIdTCPConnection owns the initial TIdIOHandler, so reassign
the
        ownership so the IOHandler is not freed when changing the
property... }

        Throttle.InsertComponent(AThread.Connection.IOHandler);
        Throttle.ChainedHandler := AThread.Connection.IOHandler;

TIdTCPConnectionAccess(AThread.Connection).FFreeIOHandlerOnDisconnect
:= False;

        AThread.Connection.IOHandler := Throttle;
    end;


Gambit

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive