disable indy TIdTCPClient connect retries in firemonkey

276 views Asked by At

i have this code to check connection to my server so code is like this:

function CheckInternet(ssip:string): boolean;
begin
result:=false;
with form1.IdTCPClient1 do
  try
    ReadTimeout:=2000;
    ConnectTimeout:=1000;
    Port:=80;
    Host:=ssip;
    Connect;
    Disconnect;
    result:=true;
  except
    on E:EIdSocketError do
      result:=false;
    end;
end;

after running: if server is online every thing is ok but if server is online i got a lot of this error:

enter image description here

there is not difference in debug or release mode! both have error also in android this cause two app crash and dont handling remain code!!.. how can i avoid this error?

1

There are 1 answers

0
Remy Lebeau On BEST ANSWER

What you see can happen only if you are calling CheckInternet() in a loop in the main UI thread and not catching raised exceptions. The popup messages are being displayed by a default exception handler within FMX when it catches an uncaught exception.

EIdSocketError is not the only type of exception that Connect() can raise. There are several other possible types, which you are not catching. You should remove the filter from your except block:

function CheckInternet(ssip:string): boolean;
begin
  result:=false;
  with form1.IdTCPClient1 do
  try
    ConnectTimeout:=1000;
    Port:=80;
    Host:=ssip;
    Connect;
    Disconnect;
    result:=true;
  except
    result:=false;
  end;
end;