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

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

  •  22-07-2023
  •  | 
  •  

Вопрос

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 ?

Это было полезно?

Решение

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;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top