Re: IdTelnet1.ReadLn in Indy 10

Giganews Newsgroups
Subject: Re: IdTelnet1.ReadLn in Indy 10
Posted by:  Remy Lebeau \(Indy Team\) (
Date: Fri, 29 Dec 2006

"Stefan Westner" <stef…> wrote in message

> in Indy 9 I could do a IdTelnet1.ReadLn.

No, you couldn't.  Not safely, anyway.  TIdTelnet has an internal
thread that continuously reads from the socket, and then triggers the
OnDataAvailable event when appropriate.  If you call ReadLn (or any
other reading method for that matter), then you have a race condition.
The calling thread can end up receiving data that the internal thread
is expecting, and vice versa.  You cannot do your own reading at all
with TIdTelnet.  You must use the OnDataAvailable event ad nothing
else.  If you must do your own reading, then you cannot use TIdTelnet.
You will have to use TIdTCPClient instead.

This applies to both Indy 9 and 10.

> In Indy 10 the ReadLn is moved to IOHandler. If I do a
> IdTelnet1.IOHandler.ReadLn my app hang.

Because you are using IdTelnet incorrectly to begin with.  Your call
to ReadLn() will hang if the internal thread swallows the terminator
character(s) that ReadLn() was expecting.



In response to

IdTelnet1.ReadLn in Indy 10 posted by Stefan Westner on Sat, 30 Dec 2006