07-20-2018, 07:15 AM
Hi all
I'm using Indy10 TCP Client to communicate with a communication partner.
To enable reading and writing at the same time I'm using IOHandler.ReadLn(Self.FETX, Self.FEncoding); inside the Execute of a TThread to read data.
And sending is done outside this Thread by the owner of the thread.
Problem is I sometimes (like every 5 - 10 Minutes) experience a hang on the IOHandler.ReadLn call which can last till I send data over the same TCPClient Instance.
Now I'm asking myself if there is a fundamental flaw in using a TCPClient like this?
I'm using Indy10 TCP Client to communicate with a communication partner.
To enable reading and writing at the same time I'm using IOHandler.ReadLn(Self.FETX, Self.FEncoding); inside the Execute of a TThread to read data.
And sending is done outside this Thread by the owner of the thread.
Problem is I sometimes (like every 5 - 10 Minutes) experience a hang on the IOHandler.ReadLn call which can last till I send data over the same TCPClient Instance.
Now I'm asking myself if there is a fundamental flaw in using a TCPClient like this?
Code:
procedure TReadingThread.Execute;
begin
while not (Terminated) do
begin
try
//Logged time here as start
Self.FData := Self.FClient.IOHandler.ReadLn(Self.FETX,1000ms, -1, Self.FEncoding);
//Logged time here as end
//In case of "hang" this can take an infinite amount of time
if (Self.FData <> '') and Assigned(Self.FOnData) then
begin
Synchronize(DataReceived);
end;
except
on EIdException do
begin
;
end;
end;
Sleep(10);
end;
end;
Code:
//Outside of TReadingThread, but same TCPClient Instance
Self.FTCPClient.IOHandler.WriteBufferOpen;
Self.FTCPClient.IOHandler.Write(Self.STX + Self.FSendDataBuffer + Self.ETX);
Self.FTCPClient.IOHandler.WriteBufferFlush;
Self.FTCPClient.IOHandler.WriteBufferClose;