Skip to content

Commit

Permalink
PING.
Browse files Browse the repository at this point in the history
  • Loading branch information
horacekj committed Mar 17, 2017
1 parent f03eb26 commit 89d17b0
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/TCPClientPanel.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -62,6 +62,7 @@ TPanelTCPClient = class
procedure OsvListParse(oblr:string; data:string);

procedure ConnetionResusced(Sender:TObject);
procedure SendPing(Sedner:TObject);

public

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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+';');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 89d17b0

Please sign in to comment.