12-02-2020, 01:15 AM
(12-02-2020, 12:32 AM)Ahmed Sayed Wrote: Is there like an equation or formula that to calculate how many milliseconds to sleep on those TCP states to mimic a speed of my selection?
Did you look at the equations that TIdInterceptThrottler itself uses internally?
Code:
procedure TIdInterceptThrottler.Receive(var ABuffer: TIdBytes);
var
LInterval: Int64;
begin
inherited Receive(ABuffer);
if RecvBitsPerSec > 0 then begin
LInterval := (Int64(Length(ABuffer)) * 8 * 1000) div RecvBitsPerSec;
while LInterval > MaxInt do begin
TIdAntiFreezeBase.Sleep(MaxInt);
Dec(LInterval, MaxInt);
end;
TIdAntiFreezeBase.Sleep(Integer(LInterval));
end;
end;
procedure TIdInterceptThrottler.Send(var ABuffer: TIdBytes);
var
LInterval: Int64;
begin
inherited Send(ABuffer);
if SendBitsPerSec > 0 then begin
LInterval := (Int64(Length(ABuffer)) * 8 * 1000) div SendBitsPerSec;
while LInterval > MaxInt do begin
TIdAntiFreezeBase.Sleep(MaxInt);
Dec(LInterval, MaxInt);
end;
TIdAntiFreezeBase.Sleep(Integer(LInterval));
end;
end;Though, a TCP connection is really not measured in bits/bytes-per-second after AFTER the connection is established. So, just use whatever sleep interval you want for the resolve/connect delay. For instance, if you want TIdTCPClient.Connect() to take 5+ seconds to complete, then just sleep for 5+ seconds.

