How to read the data?

Do so

IdTCPClient1.IOHandler.ReadLn 

So the client reads line by line, but on the last line hangs.

If you put '\n' at the end of each message on the server, then everything is OK, is this correct?

According to the idea, he should consider everything that was transferred by the server!

delphi XE3

  • data: = IdTCPClient1.IOHandler.ReadLn (# $ D # $ A) if the server answers "Hello", then the client will not exit ReadLn (# $ D # $ A) and if the server answers "Helllo" + # $ D # $ A - then in the data sign up Hello - GoldCode

1 answer 1

Try to read through IdTCPClient1.Socket.ReadLn . IdTCPClient1.Socket.ReadLn data.

  • tried - the same thing freezes - GoldCode
  • Are you reading something from the server in a loop? Or is the program just hanging on the line? - IntegralAL
  • It is logical that it hangs, as it is waiting for a newline. Therefore, they usually make it so that they know exactly how much data they need to read — for example, before a line feed or transfer the size, or to a special character. - KoVadim
  • Yes, try to first transfer the size of the data to be transferred. And after matching the size of the received data volume with the transferred size, complete the data reading by the IdTCPClient component. - IntegralAL
  • The question was whether I read the data correctly, and not why it hangs. reading data is done in a loop and in a stream. data: = IdTCPClient1.IOHandler.ReadLn (# $ D # $ A) if the server answers "Hello", then the client will not exit ReadLn (# $ D # $ A) and if the server answers "Helllo" + # $ D # $ A - then in data write Hello . GoldCode