Arduinian Posted November 12, 2010 Share Posted November 12, 2010 (edited) 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? expandcollapse popup#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 November 12, 2010 by Arduinian Link to comment Share on other sites More sharing options...
Arduinian Posted November 12, 2010 Author Share Posted November 12, 2010 I am willing to pay tens of bucks for any fix. Link to comment Share on other sites More sharing options...
Juvigy Posted November 12, 2010 Share Posted November 12, 2010 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 More sharing options...
Arduinian Posted November 12, 2010 Author Share Posted November 12, 2010 No luck, changed to higher number but still it keeps crashing after receiving a few text and sending keystrokes. Link to comment Share on other sites More sharing options...
Arduinian Posted November 12, 2010 Author Share Posted November 12, 2010 Btw, the above script was taken from http://www.autoitscript.com/autoit3/docs/functions/TCPRecv.htm, I only added the conditional statement to focus on specific windows and send a combination of keystrokes to it. Link to comment Share on other sites More sharing options...
MvGulik Posted November 12, 2010 Share Posted November 12, 2010 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 More sharing options...
Arduinian Posted November 12, 2010 Author Share Posted November 12, 2010 (edited) 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. Edited November 12, 2010 by Arduinian Link to comment Share on other sites More sharing options...
Richard Robertson Posted November 12, 2010 Share Posted November 12, 2010 When you say crash, what is the error you are receiving? Link to comment Share on other sites More sharing options...
Arduinian Posted November 14, 2010 Author Share Posted November 14, 2010 I received no error message, the program just quitted. I tried throwing some error handler inside but unsuccessful so far. Link to comment Share on other sites More sharing options...
MvGulik Posted November 14, 2010 Share Posted November 14, 2010 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now