procedure Tform1.HartTimerTimer(Sender: TObject); var CBLogin:TCBLogin; Buffer: array[1..2048] of char; begin if ClientTCP.Connected = False then exit; try ClientTCP.WriteBuffer(skOnlineCheck, 1, True); //AutoService.IOer.AddShow('向服务端发送心跳测试',[]); except AutoService.IOer.AddShow('向服务端发送心跳测试失败************************',[]); Exit; end; end; if GetTickCount - LastReturnHartTick > HartTimer.Interval * 10 then begin AutoService.IOer.AddShow('心跳超时,自动断开并重新登陆',[]); ClientLogout(); Exit; end;end;
记得要在客户端线程中刷新 var begin LastReturnHartTick := GetTickCount; end 心跳时间
procedure Tform1.HartTimerTimer(Sender: TObject);
var
CBLogin:TCBLogin;
Buffer: array[1..2048] of char;
begin
if ClientTCP.Connected = False then exit;
try
ClientTCP.WriteBuffer(skOnlineCheck, 1, True);
//AutoService.IOer.AddShow('向服务端发送心跳测试',[]);
except
AutoService.IOer.AddShow('向服务端发送心跳测试失败************************',[]);
Exit;
end;
end; if GetTickCount - LastReturnHartTick > HartTimer.Interval * 10 then
begin
AutoService.IOer.AddShow('心跳超时,自动断开并重新登陆',[]);
ClientLogout();
Exit;
end;end;
var
begin
LastReturnHartTick := GetTickCount;
end
心跳时间