Indy TIdTCPClient ConnectTimout not working

2.2k views Asked by At

I have a TIdTCPClient which is trying to connect to a host which is not online.

UPDATE:
After diving a bit deeper into WINSOCK2 it seems like this is indeed an issue which is depending on your operating system. Maybe there will be a fix in a future release. (See the comments of this question for more details)

Setup:

  • Delphi 10 Seattle
  • Windows 7 64-Bit
  • Indy 10.6.2.5311

The ConnectTimeout is set to 5000 ms so I would expect to get at least a ConnectTimeout after 5 seconds. However on my current machine it takes over 20 seconds to receive that Timeout.

So far I see that the ConnectionTimeout is handled correctly but on TIdIOHandlerStack.ConnectClient there is an WaitFor on the thread which performs the actual connection attempt. I think this is causing the delayed connection timeout, but I don't know what I could do about that. Any Ideas?

Code:

procedure TForm1.btn1Click(Sender: TObject);
begin
  try
    Self.mmo1.Lines.Add(TimeToStr(now));
    Self.idtcpclnt1.Host := '192.148.89.112';
    Self.idtcpclnt1.Port := 9200;
    Self.idtcpclnt1.Connect;
  except on E: Exception do
    Self.mmo1.Lines.Add(TimeToStr(now)+ ' : '+E.Message);
  end;
end;

procedure TForm1.idtcpclnt1Status(ASender: TObject; const AStatus: TIdStatus;
    const AStatusText: string);
begin
  Self.mmo1.Lines.Add(TimeToStr(now)+ ' : ' +AStatusText);
end;

Result of this code:

image

0

There are 0 answers