ping problem fixed

This commit is contained in:
André Mussche 2014-02-04 21:23:49 +01:00
parent 5a7310896b
commit 4fc311b4c8
3 changed files with 6 additions and 1 deletions

View file

@ -687,6 +687,8 @@ var
ws: TIdIOHandlerWebsocket;
begin
ws := IOHandler as TIdIOHandlerWebsocket;
ws.LastPingTime := Now;
//socket.io?
if SocketIOCompatible and ws.IsWebsocket then
begin
@ -1143,7 +1145,7 @@ begin
(chn.Socket.Binding.Handle <> INVALID_SOCKET) then
begin
//more than 10s nothing done? then send ping
if SecondsBetween(Now, ws.LastActivityTime) > 10 then
if SecondsBetween(Now, ws.LastPingTime) > 10 then
if chn.CheckConnection then
try
chn.Ping;

View file

@ -37,6 +37,7 @@ type
FCloseCode: Integer;
FClosing: Boolean;
FLastActivityTime: TDateTime;
FLastPingTime: TDateTime;
class var FUseSingleWriteThread: Boolean;
protected
FMessageStream: TMemoryStream;
@ -91,6 +92,7 @@ type
procedure WriteBufferFlush(AByteCount: Integer); override;
property LastActivityTime: TDateTime read FLastActivityTime write FLastActivityTime;
property LastPingTime: TDateTime read FLastPingTime write FLastPingTime;
class property UseSingleWriteThread: Boolean read FUseSingleWriteThread write FUseSingleWriteThread;
end;

View file

@ -210,6 +210,7 @@ begin
if Result then
begin
Self.IndyClient.IOHandler.InputBuffer.Clear;
Self.IndyClient.IOHandler.ReadTimeout := Self.IndyClient.ReadTimeout;
//background wait for data in single thread
TIdWebsocketMultiReadThread.Instance.AddClient(Self.IndyClient);
end;