Sunday, 24 January 2021

Detect internet access in Delphi

 

uses IdTCPClient;

function CheckInternet : Boolean;

var TCPClient : TIdTCPClient;

begin
  TCPClient := TIdTCPClient.Create (NIL);

  try
    try
      TCPClient.ReadTimeout := 2000;
      TCPClient.ConnectTimeout := 2000;
      TCPClient.Port := 80;
      TCPClient.Host := 'google.com';
      TCPClient.Connect;
      TCPClient.Disconnect;
      Result := true;

      except
        Result := false;
      end; { try / except }

    finally
      TCPClient.Free;
    end; { try / finally }
end;

No comments:

Post a Comment

zomok E-commerce system plan. Choose your online ordering system. No-risk 30 day free trial. Then USD 9/month. No credit card required.

zomok E-commerce system plan. Choose your online ordering system. No-risk 30 day free trial. Then USD 9/month. No credit card required. h...