Jump to content

$msg = GUIGetMsg() , hangs up ?

Recommended Posts

 I've run code that accesses this webpage (for years!) and its worked fine under Autoit until recently.  


I am assuming they added something to  the html code that is causing the program to hang up, but after running a trace, it stops executing at this line of code , after running for 5 to 10 seconds  in a loop.

$msg = GUIGetMsg()

Makes little sense on the face of it, but could there be something in html loaded with _IECreateEmbedded() , that could cause this?

I made no changes of any kind to the codebase, which makes me think it's the webpage contents.

The program itself  quite large and unwieldy, so I'm not posting it at this time.










Link to post
Share on other sites

Yep, thats the last line of code executing before the whole thing comes to a screaming halt. I know its odd.


No timeout, no error thrown.  Thinking maybe some stack issue, but as I said, I made NO changes to code and dont  know how the html in the page could cause that .

This is code that has run daily for YEARS without issue.

One hint,  The page load itself was taking forever, where it was instant before whatever change occured, I added



To get it to load the data , which is another clue that its something on the page causing it. Didn't need it before.

Look at the url I posted and see if there's anything in there.




Edited by Jdop
Link to post
Share on other sites

 No question its that web page, which , I think is a lot larger in terms of code size than it used  to be, 600k vs 60k.

 It hangs as I said after about 8 seconds, exactly on the

$msg = GUIGetMsg() 

line, and then goes into a high cpu usage state,  where the process continues to gobble memory.

 Seems like a strange place for code to stop running but its 100% consistent, every time.


Edited by Jdop
Link to post
Share on other sites
On 5/20/2016 at 10:17 PM, Jdop said:


 I've run code that accesses this webpage (for years!) and its worked fine under Autoit until recently.  



OK, this will help you.

Global $aURL = _HTTPGetByUrl("http://www.trade-ideas.com/SingleAlertType/NHP/New_high.html",1)
;~ _ArrayDisplay($aURL)

Func _HTTPGetByUrl($sURL, $iStartupTCP = 0, $iTcpTimeoutWithoutReceiving = 600, $iTcpTimeoutWhileReceiving = 60000)

    If $iStartupTCP Then TCPStartup()

    Local $tTimer = TimerInit()
    Local $aURL = _url2hostPage($sURL)
    Local $iError = @error
    ReDim $aURL[11][2]
    $aURL[4][0] = "WSA error"
    $aURL[5][0] = "debug type number"
    $aURL[6][0] = "debug type string"
    $aURL[7][0] = "Received data"
    $aURL[8][0] = "Total time"
    $aURL[9][0] = "Received bytes"
    $aURL[10][0] = "average chunck speed"
    If Not $aURL[0][0] Then
        $aURL[4][1] = $iError
        $aURL[5][1] = 1
        $aURL[6][1] = "url2hostPage failed"
        Return SetError(1, 0, $aURL)
    $aURL[0][0] = 10

    $iError = @error
    If $iError Then
        $aURL[4][1] = $iError
        $aURL[5][1] = 2
        $aURL[6][1] = "TCPStartup failed"
        Return SetError(2, 0, $aURL)

    Local $sName_To_IP = TCPNameToIP($aURL[1][1])
    $iError = @error
    If $iError Then
        $aURL[4][1] = $iError
        $aURL[5][1] = 3
        $aURL[6][1] = "TCPNameToIP failed"
        Return SetError(3, $iError, $aURL)

    Local $iSocket = TCPConnect($sName_To_IP, $aURL[0][1])
    $iError = @error
    If $iSocket = -1 Or $iError Then
        $aURL[4][1] = $iError
        $aURL[5][1] = 4
        $aURL[6][1] = "TCPConnect failed"
        Return SetError(4, 0, $aURL)

    Local $sCommand = "GET " & $aURL[2][1] & " HTTP/1.1" & @CRLF
    $sCommand &= "Host: " & $aURL[1][1] & @CRLF
    $sCommand &= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0 SMSviaWEB/" & @CRLF
    $sCommand &= "Referer: " & $aURL[1][1] & @CRLF
;~     $sCommand &= "Content-Encoding: gzip, deflate" & @CRLF ; remove this =)
    $sCommand &= "Connection: close" & @CRLF & @CRLF

    Local $BytesSent = TCPSend($iSocket, $sCommand)
    If $BytesSent = 0 Then
        $aURL[4][1] = @error
        $aURL[5][1] = 5
        $aURL[6][1] = "TCPSend HTTP command failed"
        Return SetError(5, 0, $aURL)

    Local $sRecv = "", $sCurrentRecv = ""
    Local $tRecv = TimerInit()
    Local $iRecvChunk = 0
    Local $tRecvChunk = TimerInit()
    Local $iErrorInLoop = 0
    Local $sError = ""
    Local $averageChunck = 0
    While 1
        If GUIGetMsg() = -3 Then ExitLoop
        $sCurrentRecv = TCPRecv($iSocket, 1024) ; 16
        If @error <> 0 Then
            $iErrorInLoop = @error
            $iError = 6
            $sError = "TCPRecv failed"
        If $sCurrentRecv <> "" Then
            $tRecv = TimerInit()
            $sRecv &= $sCurrentRecv
;~          ConsoleWrite("--- >" & $sCurrentRecv & "< --- ms.: " & TimerDiff($tRecvChunk) & @CRLF)
            If $iRecvChunk Then $averageChunck = ($averageChunck + TimerDiff($tRecvChunk)) / $iRecvChunk
            $iRecvChunk += 1
            $tRecvChunk = TimerInit()
        If $sRecv And TimerDiff($tRecv) > $iTcpTimeoutWhileReceiving Then
            $sError = "data receiving stopped ( " & $iTcpTimeoutWhileReceiving & " ms. timeout )"
            $iError = 7
        If TimerDiff($tRecv) > $iTcpTimeoutWithoutReceiving Then
            $sError = "no data received ( " & $iTcpTimeoutWithoutReceiving & " ms. timeout )"
            $iError = 8


    If $iStartupTCP Then TCPShutdown()

    $aURL[4][1] = $iErrorInLoop
    $aURL[5][1] = $iError
    $aURL[6][1] = $sError
    $aURL[7][1] = $sRecv
    $aURL[8][1] = TimerDiff($tTimer)
    $aURL[9][1] = BinaryLen(Binary($sRecv))
    $aURL[10][1] = $averageChunck
    Return SetError($iError, $aURL[9][1], $aURL)
EndFunc   ;==>_HTTPGetByUrl

Func _url2hostPage($sURL)
    Local $a[4][2]
    $a[0][0] = 3
    $a[0][1] = "" ; port # based on Protocol or URL ":" divisor
    $a[1][0] = "Host"
    $a[2][0] = "Page"
    $a[3][0] = "protocol"
    Local $iPortFor_FTP = 21 ;  File Transfer Protocol (FTP)
    Local $iPortFor_SSH = 22 ; Secure Shell (SSH)
    Local $iPortFor_SMTP = 25 ; Simple Mail Transfer Protocol (SMTP)
    Local $iPortFor_DNS = 53 ; Domain Name System (DNS) service
    Local $iPortFor_HTTP = 80 ; Hypertext Transfer Protocol (HTTP) used in the World Wide Web
    Local $iPortFor_POP3 = 110 ; Post Office Protocol (POP3)
    Local $iPortFor_NNTP = 119 ; Network News Transfer Protocol (NNTP)
    Local $iPortFor_NTP = 123 ; Network Time Protocol (NTP)
    Local $iPortFor_IMAP = 143 ; Internet Message Access Protocol (IMAP)
    Local $iPortFor_SNMP = 161 ; Simple Network Management Protocol (SNMP)
    Local $iPortFor_IRC = 194 ; Internet Relay Chat (IRC)
    Local $iPortFor_HTTPS = 443 ;  HTTP Secure (HTTPS)
    Local $i1 = StringInStr($sURL, "://")
    If Not $i1 Then
        $a[0][0] = 0
        Return SetError(1, 0, $a)
    Local $i2 = StringInStr($sURL, "/", 0, 3)
    If Not $i2 Then
        $a[0][0] = 0
        Return SetError(2, 0, $a)
    $a[1][1] = StringMid($sURL, $i1 + 3, $i2 - $i1 - 3)
    $b = StringSplit($a[1][1], ":")
    ReDim $b[3]
    $a[1][1] = $b[1]
    If Int($b[2]) Then $a[0][1] = Int($b[2]) ; port from URL
    $a[2][1] = StringTrimLeft($sURL, $i2 - 1)
    $a[3][1] = StringLeft($sURL, $i1 - 1)
    If Int($a[0][1]) = 0 Then $a[0][1] = Eval("iPortFor_" & $a[3][1]) ; port from URL not found, use protocol's port
    If Int($a[0][1]) = 0 Then $a[0][1] = 80 ; port not found, use "port 80" as default
    Return SetError(0, 0, $a)
EndFunc   ;==>_url2hostPage

so you can debug your code.

Link to post
Share on other sites
10 hours ago, Jdop said:

No website passes this test, so Im not sure what this is supposed to do for me.

The code does the TCP itself, so no libraries would be at fault. I run the code on my side and it downloaded the page. Know not why would not work for you.

Link to post
Share on other sites

Running that code for  



I get this result

WSA error|10054
debug type number|6
debug type string|TCPRecv failed
Received data|
Total time|22.2122211065389
Received bytes|0
average chunck speed|0




Edited by Jdop
Link to post
Share on other sites

 Yes, I saw that was the issue with that particular error, but still getting bad results  no matter what.  For the revised google url I get

Row|Col 0|Col 1
[4]|WSA error|-1
[5]|debug type number|6
[6]|debug type string|TCPRecv failed
[7]|Received data|
[8]|Total time|189.571072241216
[9]|Received bytes|0
[10]|average chunck speed|0

Edited by Jdop
Link to post
Share on other sites

 Nothing beyond Windows 7 Firewall, and having no issues other than this autoit program.   All sites load fine under all browsers. 


Even when the google page returns data, it still throws that [4]|WSA error|-1

Edited by Jdop
Link to post
Share on other sites

don't know how else to help, I go to http://www.trade-ideas.com/ and get:

HTTP/1.1 200 OK
Date: Tue, 24 May 2016 00:18:06 GMT
Server: Apache/2.2.22 (Fedora)
X-Powered-By: PHP/5.3.20
X-Pingback: http://www.trade-ideas.com/xmlrpc.php
... ...

so, try the code on another PC or maybe a virtual PC ( if another PC is not at hand ) to rule out your current PC producing the fault somehow.

Link to post
Share on other sites

Tried it on a VM with the most recent Autoit build, and it seems to work. 

Now I have see what the real issue is.  I'm going to install the most recent version of Autoit on my production machine and see if that makes a difference.


Edited by Jdop
Link to post
Share on other sites

Well, the problem with the code you supplied is solved by updating the install. Seems something in the old version wasn't kosher.

My problem with that website (tradeideas) remains unsolved.

Pretty sure its garbage they added to  the web page, I'd have to rewrite my code to avoid the issue.



Link to post
Share on other sites
  • 2 weeks later...

 fwiw, I was right, something that happens a lot. :lol:default_laugh.png.1111111111111111111111

Finally figured out how to deal with the garbage they inserted using the hosts file, blocking the site.  so I didn't have to rewrite  code.

Thing is, how some embedded javascript could cause  guigetmsg  to hang like that is really strange.  Some kind of timer it seems , after 10 seconds, it kicked in and hung everything.



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...