-2

There is a certain remote server. I want to get an answer from him

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Clear;

  IdTCPClient1.Host := '163.158.182.243';
  IdTCPClient1.Port := 28900;
  IdTCPClient1.Connect;
end;

procedure TForm1.IdTCPClient1Connected(Sender: TObject);
begin
  IdTCPClient1.IOHandler.Write('001');
  IdTCPClient1.IOHandler.ReadStrings(Memo1.Lines, 25, IndyTextEncoding(IdTextEncodingType.encOSDefault));
end;

The procedure requires a parameter to specify AReadLinesCount, otherwise the program stops responding

procedure TIdIOHandler.ReadStrings(ADest: TStrings; AReadLinesCount: Integer = -1;
  AByteEncoding: IIdTextEncoding = nil
  {$IFDEF STRING_IS_ANSI}; ADestEncoding: IIdTextEncoding = nil{$ENDIF}
  );

How to AReadLinesCount from the responses received

  • We have no context. What is AReadLinesCount. Please edit the question to clarify. – David Heffernan Dec 30 '16 at 08:47
  • Think about it. How is the recipient going to know how much of the data to read? How can the recipient just guess how many lines to read. That information has to be passed as well as the content. Were it me I would not use the line oriented method. I'd convert the text into bytes using some encoding, e.g. UTF8. Then I'd send the number of bytes followed by the bytes themselves. – David Heffernan Dec 30 '16 at 09:34
  • On a side note, `IndyTextEncoding(IdTextEncodingType.encOSDefault))` can be simplified to `IndyTextEncoding_OSDefault`. – Remy Lebeau Dec 30 '16 at 19:40

1 Answers1

0

The server needs to tell your client when to stop reading. There are two ways it can do that:

  1. It can send the number of lines before sending the lines themselves. You would read the number first, and then read the specified number of lines that follow.

  2. It can send a unique terminating delimiter after sending the lines. You would read lines in a loop until you reach the terminator.

You have not provided any details about the protocol you are trying to implement, so noone can tell you exactly what to write in your code to make this work.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 100.[TBBC] Master Server Version 0.5.6.101.25. Tere 25 - number of rows, but more than one – Shouldercannon Dec 30 '16 at 20:22
  • @Shouldercannon that information is completely useless. What are you trying to say? The **version** of the server is not important, what is important is the **protocol** that the server uses to communicate. You have not provided any information about that protocol. How do you expect to communicate with the server when you don't know HOW it communicates? What kind of server is it, anyway? – Remy Lebeau Dec 30 '16 at 20:27