如何使用TIdTCPClient或其他Indy客户端组件计算网站的响应时间?

时间:2014-05-14 15:13:10

标签: delphi tcp indy

我有一个应用程序,使用TIdTCPClient从给定网站发送和接收数据 - 看起来像这样:

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

其中clientRequest是动态创建的,clientResponse是服务器(所需网站)作为响应发送的内容。所以我的问题是如何计算我的TCPClient网站的平均响应时间连接到?

1 个答案:

答案 0 :(得分:3)

查看Indy的Ticks()GetTickDiff()函数,例如:

uses
  ..., IdGlobal;

var
  StartTicks: LongWord;
begin
  ...
  StartTicks := Ticks;
  TCPClient.IOHandler.ReadStream(clientResponse, size, False);
  Elapsed := GetTickDiff(StartTicks, Ticks);
  ...
end;