Delphi Indy ReadLn with timeout

Question about Indy.

I added a timeout parameter to my call TIdTCPClient ReadLnso that my thread can check that it is interrupted so often. However, if a timeout occurs, I never get any data from ReadLnfrom this point. How to reset TIdTCPClientso that it looks for the string again?

procedure TClientListner.Execute;
var
  msg : String;

begin

  while not terminated do
  begin
    msg := fSocketCon.IOHandler.ReadLn('\n', 200);
    if not fSocketCon.IOHandler.ReadLnTimedOut then
    begin
      DoSomeThing(msg);
    end;
  end;
end;
+4
source share
1 answer

Unlike C / C ++, \it is not an escape character, therefore it is '\n'not interpreted as a line feed in Delphi. This is the actual 2-character string, a character '\'followed by a character 'n'.

, #10 Indy LF:

msg := fSocketCon.IOHandler.ReadLn(#10, 200);

msg := fSocketCon.IOHandler.ReadLn(LF, 200);

, ReadLn() LF terminator:

msg := fSocketCon.IOHandler.ReadLn('', 200);

, ATimeout . ReadTimeout, , LF:

fSocketCon.IOHandler.ReadTimeout := 200;
...
msg := fSocketCon.IOHandler.ReadLn;
+11

All Articles