Sockets TWSocket需要一段时间才能重新连接
我有一个间隔为2秒的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秒钟后,插座
通过以下代码连接到:
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秒)重新连接