How to handle received data in the TCPClient ? (Delphi - Indy)

后端 未结 5 604
梦如初夏
梦如初夏 2021-02-01 22:59

When i send a message from TCPClient to a TCPServer it will be handled using OnExecute event in the server . Now i want to handle the rece

5条回答
  •  醉梦人生
    2021-02-01 23:52

    Add a TTimer. Set its Interval to 1. Write in OnTimer Event:

    procedure TForm1.Timer1Timer(Sender: TObject);
    var
    s: string;
    begin
    if not IdTCPClient1.Connected then Exit;
    if IdTCPClient1.IOHandler.InputBufferIsEmpty then Exit;
    s := IdTCPClient1.IOHandler.InputBufferAsString;
    Memo1.Lines.Add('Received: ' + s);
    end;
    

    Don't set Timer.Interval something else 1. Because, the received data deletes after some milliseconds.

提交回复
热议问题