12-02-2020, 04:10 PM
(12-02-2020, 01:15 AM)rlebeau Wrote:(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.
Thanks, for the example.
But what I meant is that, I have an internet speed of 30MB my transfer speed when I download anything is between 2.5 and 3.5 MB. I know Egypt still does not have fast internet connections, so, let's say that I want to mimic a speed of 512 kbps instead of 3.5 MB I believe if I used your example I should get an exact result on how much should I delay the request on the resolve DNS state or connect. Will that work and simulate the speed that I want?

