Jump to content
Sign in to follow this  

checks and retries a connection

Recommended Posts


checks and retries a connection x times - plus extras

;checks and retries a connection x times - plus extras
;some scriplets i've put together plus some of my own
;not a total Inet errors solution - but it greatly helps
;only works if website supports file size return
;by ripdad, feb 20, 2010
#include <Inet.au3>
Global $ck_count = 0; init loop counter
Func Check_Connect(); checks if there is indeed a connection
    $ck_count = $ck_count + 1; advance loop counter
    $CkConnect1 = InetGetSize("http://www.somesite.com/somefile.txt")
    If Not $CkConnect1 <> 0 Then; if no response then
        $CkConnect2 = Ping("http://www.somesite.com", 250); second check
        If Not $CkConnect2 Then; if still no response then
            Connection_Error(); go sleep for awhile
Func Download_File()
    Local $hdownload
    $GetFile = "http://www.somesite.com/somefile.txt"
    $SourceSize = InetGetSize($GetFile)
    $hdownload = InetGet($GetFile, @DesktopDir & '\somefile.txt', 1, 1)
        TrayTip("Downloading File   -   " & Int(InetGetInfo($hdownload, 0) / $SourceSize * 100) & '%' & "  Done", $GetFile, 10, 5000)
    Until InetGetInfo($hdownload, 2)
    If InetGetInfo($hdownload, 0) < $SourceSize Then; checks if connection was lost during download with size compare
        TrayTip("", "", 5); closes traytip
        Connection_Error(); go sleep for awhile
Func Connection_Error()
    If $ck_count = 5 Then MsgBox(16, "No Connection", "Retried " & $ck_count & " Times With No Success - Exiting", 10); possible logging here
    If $ck_count = 5 Then Exit;  escape with loop count. change $ck_count = 5 to your preference
    MsgBox(16, "Connection Error", "Will Try Again in 5 Minutes" & @CRLF & @CRLF & "Retry Number: " & $ck_count, 10)
    Sleep(300000);  wait 5 minutes - change sleep value to your preference
    Check_Connect(); try connection again

* oops, added \ in: $hdownload = InetGet($GetFile, @DesktopDir & 'somefile.txt', 1, 1)

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.