Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simulating low bandwidth with TIdHTTP
#6
(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.

Reply


Messages In This Thread
RE: Simulating low bandwidth with TIdHTTP - by rlebeau - 12-02-2020, 01:15 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)