Jump to content

AutoIt script keep crashing.


 Share

Recommended Posts

I modified a script that listens to port 8888 and upon receiving any text would grab a specific application windows and sends a combination of keystrokes to it. My problem is, the script keeps quitting after a number of time upon receiving text and sending keystrokes. I am running Windows Vista and tried both running script and compiling the script into executeable. Here's my code and am I doing anything wrong?

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

;==============================================
;==============================================
;SERVER!! Start Me First !!!!!!!!!!!!!!!
;==============================================
;==============================================

Example()

Func Example()
; Set Some reusable info
; Set your Public IP address (@IPAddress1) here.
;† †Local $szServerPC = @ComputerName
;† †Local $szIPADDRESS = TCPNameToIP($szServerPC)
Local $szIPADDRESS = @IPAddress1
;Local $nPORT = 33891
Local $nPORT = 8888
Local $MainSocket, $GOOEY, $edit, $ConnectedSocket, $szIP_Accepted
Local $msg, $recv

; Start The TCP Services
;==============================================
TCPStartup()

; Create a Listening "SOCKET".
; ††Using your IP Address and Port 33891.
;==============================================
$MainSocket = TCPListen($szIPADDRESS, $nPORT)

; If the Socket creation fails, exit.
If $MainSocket = -1 Then Exit

; Create a GUI for messages
;==============================================
$GOOEY = GUICreate("My Server (IP: " & $szIPADDRESS & ")", 300, 200)
$edit = GUICtrlCreateEdit("", 10, 10, 280, 180)
GUISetState()

; Initialize a variable to represent a connection
;==============================================
$ConnectedSocket = -1

;Wait for and Accept a connection
;==============================================
Do
$ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1


; Get IP of client connecting
$szIP_Accepted = SocketToIP($ConnectedSocket)

; GUI Message Loop
;==============================================
While 1
$msg = GUIGetMsg()

; GUI Closed
;--------------------
If $msg = $GUI_EVENT_CLOSE Then ExitLoop

; Try to receive (up to) 2048 bytes
;----------------------------------------------------------------

$recv = TCPRecv($ConnectedSocket, 2048)
; If the receive failed with @error then the socket has disconnected
;----------------------------------------------------------------
If @error Then ExitLoop

; Update the edit control with what we have received
;----------------------------------------------------------------
If $recv <> "" Then
    ;MsgBox(0, $recv, '"' & $recv & '"')
    GUICtrlSetData($edit, $szIP_Accepted & " > " & $recv & @CRLF & GUICtrlRead($edit))
    If $recv = "update_watchout" Then
        WinActivate("WATCHOUT")
        Send("^d")
        Sleep(10000)
        WinActivate("WATCHOUT")
        Send("^b")
    ;ElseIf $recv = "standby_watchout" Then
        ;WinActivate("WATCHOUT")
        ;Send("^b")
    ElseIf $recv = "reset_folder" Then
        DirCopy("D:/Original", "D:/Photos", 1)
        Sleep(1000);
        WinActivate("WATCHOUT")
        Send("^b")
    EndIf
EndIf
WEnd


If $ConnectedSocket <> -1 Then TCPCloseSocket($ConnectedSocket)
TCPShutdown()
EndFunc
;==>Example

; Function to return IP Address from a connected socket.
;----------------------------------------------------------------------
Func SocketToIP($SHOCKET)
Local $sockaddr, $aRet

$sockaddr = DllStructCreate("short;ushort;uint;char[8]")

$aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
If Not @error And $aRet[0] = 0 Then
$aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr,3))
If Not @error Then $aRet = $aRet[0]
Else
$aRet = 0
EndIf

$sockaddr = 0

Return $aRet
EndFunc
;==>SocketToIP
Edited by Arduinian
Link to comment
Share on other sites

Not quite good with this but did you try to change that part :

; Try to receive (up to) 2048 bytes

;----------------------------------------------------------------

$recv = TCPRecv($ConnectedSocket, 2048)

Maybe remove the 2048 limit?

Link to comment
Share on other sites

Maybe next time it might be more usefully to start with,

"Btw, the above script was taken from ..."

instead of,

"I created a script that ..."

just a thought.

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Maybe next time it might be more usefully to start with,

"Btw, the above script was taken from ..."

instead of,

"I created a script that ..."

just a thought.

Point taken! I was too quick to hit the send button and a couple of minutes later, the edit button has gone.

Update: edited the post. :graduated:

Edited by Arduinian
Link to comment
Share on other sites

While your waiting for someone else to replay you might like to take the time to read trough this page.

http://www.autoitscript.com/wiki/FAQ#How_can_I_debug_my_script.3F

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...