I'm trying to change the connection type from the string (ReadLn
) to an array of byte (ReadByte
) and so I have a problem with the timeout property of TIdTCPServer
.
How can identify timeout event in ReadByte mode and handle it? In ReadLn Mode by adding this line "AContext.Connection.IOHandler.ReadLnTimedout" can determine Timeout event but in ReadByte mode can not do this. After timeout by checking "ReadLnTimedout"
The other problem is deadlocking my program when trying to deactivate TIdTCPServer
by setting Active := false
. My program is blocking at this line :
AContext.Connection.IOHandler.ReadBytes(byte_buffer,-1,false);
And I can not get control of my code.
Here is my sample code
getdata1:
try
AddTo_memo1('wait to receive packet');
AContext.Connection.IOHandler.ReadBytes(byte_buffer,-1,false);
AddTo_memo1('receive packet');
except
on e : Exception do
begin
AddTo_memo1('receive packet exc');
//do something...
raise;
end;
end;
if AContext.Connection.IOHandler.ReadLnTimedout then goto getdata1;
AddTo_memo1('receive packet without time out');
And after executing in memo1 I have:
wait to receive packet
wait to receive packet
receive packet
receive packet without time out