Delphi (Indy) Clients sends server request, how to wait for response?
client, delphi, indy, wait
Solution
The client can read the response with the IOHandler.Readxxx methods, most of them allow to set a timeout. The read timeout can also be specified on the IdTCPClient.IOHandler directly.
procedure TForm1.ReadTimerElapsed(Sender: TObject);
var
S: String;
begin
...
// connect
IdTCPClient1.Connect;
// send data
...
// use one of the Read methods to read the response.
// some methods have a timeout parameter,
// and others set a timeout flag
S := IdTCPClient1.IOHandler.ReadLn(...);
if IdTCPClient1.IOHandler.ReadLnTimedOut then
...
else
...
end;
See also: How can I wait for a string from a server with IdTCPClient?
Problem
I have just managed to get the client (IdTCPClient) to send a message to the server (IdTCPServer) as required. But how do I get the client to wait for a response, or time out appropriately? Cheers, Adrian