I have a problem with IdTelnet (indy 10.1). I can't read the data from a server in Unicode mode. and now I want to write the telnet terminal with IdTCPClient.
The server sometimes send one line and sometimes more and more lines. But there is not a fixed time between sending.
Now my problem is that when I must read data from InBuffer.
Or when I must use the ReadLn function to read the data from the server, how many times must I run the ReadLn?
TIdTelnet
is a multithreaded component. It has an internal thread that continuously reads from the socket, firing theTIdTelnet.OnDataAvailable
event whenever a buffer of data is available.TIdTelnet
is aTIdTCPClient
descendant. Look in the IdTelnet.pas source file to see how it is implemented. You can do something similar in your own code, callingTIdIOHandler.ReadLn()
in your own thread, eg:If you don't want to use a thread, then you can use a timer instead. To make sure your timer thread (such as the main thread) is not blocked unnecessarily, use the
TIdIOHandler.CheckForDataOnSource()
method with a small timeout whenever theTIdIOHandler.InputBuffer
is empty, before then callingTIdIOHandler.ReadLn()
only when data is available, eg: