Jump to content

Recommended Posts

I dusted off an old script I wrote in 2017, which still works.

However, I noticed that it could be much faster if I incorporate a way to have _InetGetSource timeout after a second of two.

I read some older posts on this subject, but couldn't determine a simple and elegant method of achieving my goal.

Thank you in advance for any constructive ideas you have to offer.

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to post
Share on other sites
1 hour ago, taurus905 said:

incorporate a way to have _InetGetSource timeout after a second of two

I don't know of a way to change the timeout settings for the _InetGetSource() function itself.  However, if I needed control over HTTP request timeouts, I would most likely use the WinHTTPRequest object instead of _InetGetSource().  Specifically, I would use the SetTimeouts method of the object to set the desired timeouts.  As you can see HERE, there's more than 1 timeout for a request.  The SetTimeouts method allows you to set them as you desire.

It would look something like this:

...
$oHttp.SetTimeouts(5000, 5000, 5000, 5000)
...

 

Edited by TheXman
Link to post
Share on other sites
On 10/1/2022 at 1:28 PM, TheXman said:

However, if I needed control over HTTP request timeouts, I would most likely use the WinHTTPRequest object instead of _InetGetSource().

@TheXman Thank you for "once again" pointing me in the right direction.

Using the WinHTTPRequest object is much cleaner and gives me more control.

I also found a post by @Nine that reminded me of "object error handling" which I needed in this case.

taurus905

 

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to post
Share on other sites
On 10/1/2022 at 2:15 PM, taurus905 said:

it could be much faster if I incorporate a way to have _InetGetSource timeout after a second of two

..or, Fork / IPC, those pesky time consuming tasks.

I know the question got answered but, ... I think the above is a good idea anyway.

Edited by argumentum
Link to post
Share on other sites
1 hour ago, argumentum said:

I know the question got answered but, ... I think the above is a good idea anyway.

Thank you @argumentum Please elaborate or just point me in the right direction.

I'd love to learn how to  "Fork / IPC, those pesky time consuming tasks."

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to post
Share on other sites
Func __Example1A()
    ConsoleWrite(__InetGet("https://www.autoitscript.com/forum/")& @CRLF)
;   ConsoleWrite(__InetGet("https://www.autoitscript.com/forum/", 2000)& @CRLF)
EndFunc

Func __InetGet($e_Url, $e_TimeOut = 10000)
    Local $e_FPath = @ScriptDir & '\Temp_InetGet.txt'
    If Not FileExists($e_FPath) Then
        Local $e_FOpen = FileOpen($e_FPath, 1)
        FileClose($e_FOpen)
    Endif

    Local $e_TFlag = True
    Local $e_IGetData = InetGet($e_Url, $e_FPath, 1, 1)
    Local $e_Timer = TimerInit()
    Do
        If TimerDiff( $e_Timer) > $e_TimeOut Then
            $e_TFlag = False
            ExitLoop
        EndIf
        Sleep(10)
    Until InetGetInfo($e_IGetData, 2)

    Local $iMsg = '@error: Timeout'
    If $e_TFlag Then $iMsg = FileRead($e_FPath)

    InetClose($e_IGetData)
    FileDelete($e_FPath)
    Return $iMsg
EndFunc

 

Link to post
Share on other sites

@jugador I'm always looking for new ways to complete my tasks.

I will give your solution a try later today.

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...