简体   繁体   English

Indy TIdTCPClient ConnectTimout不起作用

[英]Indy TIdTCPClient ConnectTimout not working

I have a TIdTCPClient which is trying to connect to a host which is not online. 我有一个TIdTCPClient,它试图连接到不在线的主机。

UPDATE: 更新:
After diving a bit deeper into WINSOCK2 it seems like this is indeed an issue which is depending on your operating system. 在深入研究WINSOCK2之后,似乎确实是一个问题,具体取决于您的操作系统。 Maybe there will be a fix in a future release. 也许将来的版本中会有修复程序。 (See the comments of this question for more details) (有关更多详细信息,请参阅此问题的评论)

Setup: 设定:

  • Delphi 10 Seattle 西雅图德尔福10号酒店
  • Windows 7 64-Bit Windows 7 64位
  • Indy 10.6.2.5311 印第10.6.2.5311

The ConnectTimeout is set to 5000 ms so I would expect to get at least a ConnectTimeout after 5 seconds. ConnectTimeout设置为5000 ms,因此我希望5秒后至少获得一个ConnectTimeout。 However on my current machine it takes over 20 seconds to receive that Timeout. 但是,在我当前的计算机上,需要超过20秒才能收到该超时信息。

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. 到目前为止,我看到ConnectionTimeout的处理正确,但是在TIdIOHandlerStack.ConnectClient上,执行实际连接尝试的线程上有一个WaitFor 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: 此代码的结果:

图片

If the destination is a firewall and the firewall is enabled, you must disable the firewall. 如果目标是防火墙并且启用了防火墙,则必须禁用防火墙。

Instead of disabling the firewall, you must open the appropriate ports. 必须禁用适当的端口,而不是禁用防火墙。 However, the risks are high . 但是,风险很高

Because it becomes more permeable .( Hack ) 因为它变得更具渗透性 。( Hack

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM