MSI Factory 2.3

HTTP.TestConnection

HTTP.TestConnection

This is the first topic This is the last topic  

HTTP.TestConnection

This is the first topic This is the last topic  

OverviewExamples

boolean HTTP.TestConnection (

string URL,

number Timeout = 20,

number Port = 80,

table   AuthData = nil,

table   ProxyData = nil )

Example 1

IsConnected = HTTP.TestConnection("http://www.google.ca", 20, 80, nil, nil);

if (IsConnected == false) then

   Dialog.Message("Notice", "No Internet connection was detected.");

end

Checks the user's Internet connection by trying to connect to the site "http://www.google.ca." If the connection fails, a dialog would be displayed notifying the user.

Example 2

-- Check to see if the user is connected to the internet

connected = HTTP.TestConnection("http://www.indigorose.com", 20, 80, nil, nil);

 

-- If they are connected.

if connected then

   -- Download a file to their temporary directory.

   StatusDlg.Show(MB_ICONNONE, false);

   HTTP.Download("http://www.indigorose.com/setup.exe", _TempFolder.."\\setup.exe", MODE_BINARY, 20, 80, nil, nil, nil);

 

   -- Get any error codes that may have been returned by the download action.

   error = Application.GetLastError();

   StatusDlg.Hide();

 

 

   -- If there was an error during the download, display the error message.

   if error ~= 0 then

       result = Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);

 

   -- If there was no error during the download.

   else

       --Get the CRC value of the downloaded file.

       crc_value = File.GetCRC(_TempFolder.."\\setup.exe");

       -- Check to see if the CRC value matches it's expected value.

       if crc_value == 824907888 then

 

           -- Run the executable that was downloaded.

           File.Run(_TempFolder.."\\setup.exe", "", "", SW_SHOWNORMAL, true);

 

 

       -- The CRC value does not match. Display an error message to the user.

       else

           result = Dialog.Message("Error", "The downloaded file is incomplete. Please try downloading again.", MB_OK, MB_ICONSTOP, MB_DEFBUTTON1);

       end

   end

 

-- Display a notice informing them that they are not connected.

else

   Dialog.Message("Internet Error", "You are not connected to the internet. Please connect to download.");

end

This example first checks to see if the user has an internet connection using the HTTP.TestConnection action. If they do, a file is downloaded to their temporary directory. That file is then checked to make sure it is complete and not corrupt before launching it. A series of checks are performed in this script to handle any errors that occur and displays notification messages to the user if any actions fail.

Note: _TempFolder is a built-in variable that contains the path to the user's system "Temp" folder.

See also: Related Actions


Learn More: Indigo Rose Software - MSI Factory - Buy Now - Contact Us