From 89d17b0f6f776453652ef870f4eeacd2df5ab9a7 Mon Sep 17 00:00:00 2001 From: Jan Horacek Date: Fri, 17 Mar 2017 17:17:18 +0100 Subject: [PATCH] PING. --- src/TCPClientPanel.pas | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/TCPClientPanel.pas b/src/TCPClientPanel.pas index ee102dc..86840c5 100644 --- a/src/TCPClientPanel.pas +++ b/src/TCPClientPanel.pas @@ -15,7 +15,7 @@ interface const _DEFAULT_PORT = 5896; - _PING_TIMER_PERIOD_MS = 5000; + _PING_TIMER_PERIOD_MS = 20000; // tady jsou vyjmenovane vsechny verze protokoluk pripojeni k serveru, ktere klient podporuje protocol_version_accept : array[0..0] of string = @@ -62,6 +62,7 @@ TPanelTCPClient = class procedure OsvListParse(oblr:string; data:string); procedure ConnetionResusced(Sender:TObject); + procedure SendPing(Sedner:TObject); public @@ -122,6 +123,11 @@ constructor TPanelTCPClient.Create(); Self.parsed := TStringList.Create; + Self.pingTimer := TTimer.Create(nil); + Self.pingTimer.Enabled := false; + Self.pingTimer.Interval := _PING_TIMER_PERIOD_MS; + Self.pingTimer.OnTimer := Self.SendPing; + Self.tcpClient := TIdTCPClient.Create(nil); Self.tcpClient.OnConnected := Self.OnTcpClientConnected; Self.tcpClient.OnDisconnected := Self.OnTcpClientDisconnected; @@ -158,18 +164,14 @@ destructor TPanelTCPClient.Destroy(); try if (Assigned(Self.tcpClient)) then FreeAndNil(Self.tcpClient); - except - end; - - try if (Assigned(Self.parsed)) then FreeAndNil(Self.parsed); - except + Self.pingTimer.Free(); + finally + inherited; end; - - inherited Destroy(); end;//dtor //////////////////////////////////////////////////////////////////////////////// @@ -252,6 +254,7 @@ procedure TPanelTCPClient.OnTcpClientConnected(Sender: TObject); F_Main.A_Disconnect.Enabled := true; Self.fstatus := TPanelConnectionStatus.handshake; + Self.pingTimer.Enabled := true; // send handshake Self.SendLn('-;HELLO;'+Self._PROTOCOL_VERSION+';'); @@ -279,6 +282,7 @@ procedure TPanelTCPClient.OnTcpClientDisconnected(Sender: TObject); F_SprToSlot.Close(); Self.fstatus := TPanelConnectionStatus.closed; + Self.pingTimer.Enabled := false; F_Main.A_Connect.Enabled := true; F_Main.A_ReAuth.Enabled := false; @@ -910,6 +914,18 @@ procedure TPanelTCPClient.Update(); //////////////////////////////////////////////////////////////////////////////// +procedure TPanelTCPClient.SendPing(Sedner:TObject); +begin + try + if (Self.tcpClient.Connected) then + Self.SendLn('-;PING'); + except + + end; +end; + +//////////////////////////////////////////////////////////////////////////////// + initialization PanelTCPClient := TPanelTCPClient.Create;