How to calculate response time from website using TIdTCPClient or another Indy client component?

StackOverflow https://stackoverflow.com/questions/23658648

  •  22-07-2023
  •  | 
  •  

Question

I have an application that sends and receives data from a given website with TIdTCPClient - looks like this :

TCPClient.Host := myHost;
TCPClient.Port := myPort;
TCPClient.Connect;
TCPClient.IOHandler.Write(clientRequest);
TCPClient.IOHandler.ReadStream(clientResponse, size, False);

where clientRequest is created dynamically and clientResponse is what the server (the wanted website) sends as a response.So my question is how can I calculate the average response time from the website my TCPClient has connected to ?

Était-ce utile?

La solution

Look at Indy's Ticks() and GetTickDiff() functions, for example:

uses
  ..., IdGlobal;

var
  StartTicks: LongWord;
begin
  ...
  StartTicks := Ticks;
  TCPClient.IOHandler.ReadStream(clientResponse, size, False);
  Elapsed := GetTickDiff(StartTicks, Ticks);
  ...
end;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top