Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sockets TWSocket需要一段时间才能重新连接_Sockets_Delphi_Timer_Delphi 10.3 Rio - Fatal编程技术网

Sockets TWSocket需要一段时间才能重新连接

Sockets TWSocket需要一段时间才能重新连接,sockets,delphi,timer,delphi-10.3-rio,Sockets,Delphi,Timer,Delphi 10.3 Rio,我有一个间隔为2秒的计时器。2秒钟后,插座通过以下代码连接到: procedure TForm1.Timer1Timer(Sender: TObject); begin Timer1.Enabled := false; if WSocket1.State = wsClosed then begin try WSocket1.Connect; except WSocket1.abort; end; end else if WSoc

我有一个间隔为2秒的
计时器。2秒钟后,
插座
通过以下代码连接到:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := false;
  if WSocket1.State = wsClosed then
  begin
    try
      WSocket1.Connect;
    except
      WSocket1.abort;
    end;
  end
  else if WSocket1.State = wsConnected then
  begin
      //send data
  end;    
  Timer1.Enabled := true;    
end;
这将按预期工作,并按预期在大约2秒钟内连接,然后后续执行将发送数据

但是,如果我实际断开
插座上的设备并重新连接,重新连接大约需要3分钟。这不是设备,因为重新启动程序会在大约2秒钟后再次重新连接套接字

我曾尝试将2秒间隔改为2秒左右的任意数字,例如1937毫秒,以查看这是否会产生影响,但问题仍然存在

所以我的问题是,如何确保它在初始连接时以相同的时间(大约2秒)重新连接