sd333221 Posted July 16, 2006 Share Posted July 16, 2006 Hi guyz, i need your competent help one more time I made a remote script, using some things in the scripts 'n 'scraps section. It contains a server on wich i can execute a command, and a client which executes the command, here it is: ;Client: Global $MainSocket Local $MaxLength = 512; Maximum Length Of Text Local $Port = 50911; Port Number Local $Server = @IPAddress1; Server IpAddress TCPStartup() $MainSocket = TCPConnect($Server, $Port) ;TCPSend($MainSocket, "~newuser") While 1 $Data = TCPRecv($MainSocket, $MaxLength) If $Data = "~bye" Then Sleep(1) Exit ElseIf $Data <> "" Then ; If A command (something unconditional) is recieved $parameter = $data Run( "syn.exe " & $parameter , "/") ; <- Run the Programm Sleep(15000) ; <- For 15 secounds ProcessClose( "syn.exe") EndIf WEnd Func OnAutoItExit() If $MainSocket <> - 1 Then TCPSend($MainSocket, "~bye") TCPCloseSocket($MainSocket) EndIf TCPShutdown() EndFunc;==>OnAutoItExit expandcollapse popup;Server: HotKeySet("{F5}", "SendCommand") ;<- The Command Function Global Const $Port = 50911 Global $MaxConc = 100 Global $MainSocket = TCPStartServer($Port, $MaxConc) If @Error <> 0 Then Exit MsgBox(16, "Error", "Server unable to initialize.") Global Const $MaxLength = 512 Global $ConnectedSocket[$MaxConc] Global $CurrentSocket = 0 Local $Track = 0 Global Const $MaxConnection = ($MaxConc - 1) For $Track = 0 To $MaxConnection Step 1 $ConnectedSocket[$Track] = -1 Next While 1 $ConnectedSocket[$CurrentSocket] = TCPAccept($MainSocket) If $ConnectedSocket[$CurrentSocket] <> -1 Then $CurrentSocket = SocketSearch() EndIf $Track = 0 For $Track = 0 To $MaxConnection Step 1 If $ConnectedSocket[$Track] <> - 1 Then $Data = TCPRecv($ConnectedSocket[$Track], $MaxLength) If $Data = "~bye" Then TCPCloseSocket($ConnectedSocket[$Track]) $ConnectedSocket[$Track] = -1 $CurrentSocket = SocketSearch() ElseIf $Data <> "" Then TCPSendMessageAll($MaxConnection, $Data) EndIf EndIf Next WEnd Func TCPSendMessageAll($ConnectionLimit, $Data) Local $Track = 0 For $Track = 0 To $ConnectionLimit Step 1 If $ConnectedSocket[$Track] <> - 1 Then TCPSend($ConnectedSocket[$Track], $Data) Next EndFunc ;==>TCPSendMessageAll Func TCPStartServer($Port, $MaxConnect = 1) Local $Socket $Socket = TCPStartup() Select Case $Socket = 0 SetError(@Error) Return -1 EndSelect $Socket = TCPListen(@IpAddress1, $Port, $MaxConnect) Select Case $Socket = -1 SetError(@Error) Return 0 EndSelect SetError(0) Return $Socket EndFunc Func SocketSearch() Local $Track = 0 For $Track = 0 To $MaxConnection Step 1 If $ConnectedSocket[$Track] = -1 Then Return $Track Else ; Socket In Use EndIf Next EndFunc ;==>SocketSearch Func SendCommand() ;<- The function which send the command TCPSendMessageAll("", "Test Run!") Return EndFunc My Problem is: The script works so far, if i press f5 on the server, the client executes the programm, but it only works once, if i press f5 a secound time the program doesent execute a secound time... Also i would need something to show how many users are connected. Thank you for your help! Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 16, 2006 Share Posted July 16, 2006 Hi guyz, i need your competent help one more time I made a remote script, using some things in the scripts 'n 'scraps section. It contains a server on wich i can execute a command, and a client which executes the command, here it is: ;Client: Global $MainSocket Local $MaxLength = 512; Maximum Length Of Text Local $Port = 50911; Port Number Local $Server = @IPAddress1; Server IpAddress TCPStartup() $MainSocket = TCPConnect($Server, $Port) ;TCPSend($MainSocket, "~newuser") While 1 $Data = TCPRecv($MainSocket, $MaxLength) If $Data = "~bye" Then Sleep(1) Exit ElseIf $Data <> "" Then ; If A command (something unconditional) is recieved $parameter = $data Run( "syn.exe " & $parameter , "/"); <- Run the Programm Sleep(15000) ; <- For 15 secounds ProcessClose( "syn.exe") EndIf WEnd Func OnAutoItExit() If $MainSocket <> - 1 Then TCPSend($MainSocket, "~bye") TCPCloseSocket($MainSocket) EndIf TCPShutdown() EndFunc;==>OnAutoItExit CODE ;Server: HotKeySet("{F5}", "SendCommand") ;<- The Command Function Global Const $Port = 50911 Global $MaxConc = 100 Global $MainSocket = TCPStartServer($Port, $MaxConc) If @Error <> 0 Then Exit MsgBox(16, "Error", "Server unable to initialize.") Global Const $MaxLength = 512 Global $ConnectedSocket[$MaxConc] Global $CurrentSocket = 0 Local $Track = 0 Global Const $MaxConnection = ($MaxConc - 1) For $Track = 0 To $MaxConnection Step 1 $ConnectedSocket[$Track] = -1 Next While 1 $ConnectedSocket[$CurrentSocket] = TCPAccept($MainSocket) If $ConnectedSocket[$CurrentSocket] <> -1 Then $CurrentSocket = SocketSearch() EndIf $Track = 0 For $Track = 0 To $MaxConnection Step 1 If $ConnectedSocket[$Track] <> - 1 Then $Data = TCPRecv($ConnectedSocket[$Track], $MaxLength) If $Data = "~bye" Then TCPCloseSocket($ConnectedSocket[$Track]) $ConnectedSocket[$Track] = -1 $CurrentSocket = SocketSearch() ElseIf $Data <> "" Then TCPSendMessageAll($MaxConnection, $Data) EndIf EndIf Next WEnd Func TCPSendMessageAll($ConnectionLimit, $Data) Local $Track = 0 For $Track = 0 To $ConnectionLimit Step 1 If $ConnectedSocket[$Track] <> - 1 Then TCPSend($ConnectedSocket[$Track], $Data) Next EndFunc ;==>TCPSendMessageAll Func TCPStartServer($Port, $MaxConnect = 1) Local $Socket $Socket = TCPStartup() Select Case $Socket = 0 SetError(@Error) Return -1 EndSelect $Socket = TCPListen(@IpAddress1, $Port, $MaxConnect) Select Case $Socket = -1 SetError(@Error) Return 0 EndSelect SetError(0) Return $Socket EndFunc Func SocketSearch() Local $Track = 0 For $Track = 0 To $MaxConnection Step 1 If $ConnectedSocket[$Track] = -1 Then Return $Track Else ; Socket In Use EndIf Next EndFunc ;==>SocketSearch Func SendCommand() ;<- The function which send the command TCPSendMessageAll("", "Test Run!") Return EndFunc My Problem is: The script works so far, if i press f5 on the server, the client executes the programm, but it only works once, if i press f5 a secound time the program doesent execute a secound time... Also i would need something to show how many users are connected. Thank you for your help! Inside SendCommand(), you are using the following command to call a function: TCPSendMessageAll("", "Test Run!") Note the null for the first parameter, then look at the funciton that was called: Func TCPSendMessageAll($ConnectionLimit, $Data) Local $Track = 0 For $Track = 0 To $ConnectionLimit Step 1 If $ConnectedSocket[$Track] <> - 1 Then TCPSend($ConnectedSocket[$Track], $Data) Next EndFunc ;==>TCPSendMessageAll So you have, in effect: For $Track = 0 To "" Step 1 Jus' don' look right, no sir'ee... Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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