twiztedshane Posted April 8, 2012 Share Posted April 8, 2012 (edited) So I'm new to AutoIT (and I'm just your average teen:P) and I'm working on a TCP server based on SloppyProgrammer's SloppyServer.I've coded a few modifications (simple one's,really) and it all seems to work. Since i haven't really coded a client, I'm using NetCat to send the commands.. I can't get either the TCPSend Command OR the _Payload function to work. I'm running AutoIT v3.3.8.1 on a Windows 7 Machine, using SciTE Version 2.28 (if that helps).Please respond =/ . expandcollapse popup;Based on SloppyProgrammer's SloppyServer Global $l_IP = @IPAddress1 ; Set the listening IP Global $conned = False ; Set the conned var to false (really no use for this... Used it in an older version. will be removed soon.) Global $ConnectedSocket = "" Global $myPayload Global $pack TCPStartUp() ; Starts TCP services $MainSocket = TCPListen ($l_IP, 12345, 100 ) ; Start a listening socket If $MainSocket = -1 Then Exit ; If a socket can't be created, exit the server EndIf _waitForConn() ; Start the loop that makes the program look for clients. Func _waitForConn() While $conned = False ; Look for client connection loop $ConnectedSocket = TCPAccept ($MainSocket) ; Check if somebody wants to connect If $ConnectedSocket >= 0 Then ; If a client tries to connect, let him do so. Beep(900,2000) TrayTip("Server", "Client Connected", 5, 1) ; Make a beep and tooltip (for debugging purposes) $conned = True ; Set the conned var to true (really no use for this... Used it in an older version. will be removed soon.) _iAmConned() ; Start the connected loop. EndIf WEnd EndFunc Func _iAmConned() While $conned = True ; If connected, then... $pack = TCPRecv ($ConnectedSocket, 2048) ; Recive packages... If $pack <> "" Then _payload($pack) ; Open them and check if they are empty. If they are NOT empty, run the payload function. _TCPdebug() TCPSend($MainSocket,"You are connected.") EndIf WEnd EndFunc ;this part doesn't seem to work no matter what i try.. Func _payload($myPayload) ; Starts the payload function. Switch $myPayload ; Check the contents of the last recived package. Case "Hello" ; If the package contained the message "Hello" then TCPSend($ConnectedSocket,"Hi There!") ; Do this TCPSend($ConnectedSocket, "Opening Notepad..") Run("notepad.exe") ; ... ; Do something Case "Adios Amigo" ; If the package contained the message "Adios Amigo" then TCPCloseSocket($ConnectedSocket) ; Do something ; ... ; Do something ; ... ; Do something Else TCPSend($ConnectedSocket, "I have no idea what you are talking about.") ;Else EndSwitch ; More can be added... EndFunc Func _resetConnection() TCPCloseSocket ($ConnectedSocket) ; Closes the socket $ConnectedSocket = -1 ; Resets the ConnectedSocket placeholder $conned = False ; Set the conned var to false (really no use for this... Used it in an older version. will be removed soon.) _waitForConn() ; Go back to the "searching for a connection" function. EndFunc Func _TCPdebug() ;MsgBox(0,"Client Sent",$myPayload) ;For Debugging purposes TrayTip("Server Debug", 'Message: ' & $pack, 300, 1) EndFunc Edited April 8, 2012 by twiztedshane Link to comment Share on other sites More sharing options...
qsek Posted April 8, 2012 Share Posted April 8, 2012 works for me here, at least it connects. I used telnet as client. If you cant get a connection, its likely that your firewall or router is blocking the port. This may also interst you: Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite Link to comment Share on other sites More sharing options...
twiztedshane Posted April 9, 2012 Author Share Posted April 9, 2012 Guten tag! Well, that's not my problem at all. (I'm not a noob at these stuff, you know). It DOES run and it DOES open a connection BUT it does NOT respond when i issue any of the commands ("Hello"- should respond with "Hi there!" and then start Notepad, "Adios Amigo"-which terminates the connection, and if it's not either of those two, respond with "I have no idea what you are talking about."). I've been trying to figure out what's wrong but i can't seem to find the bug. Link to comment Share on other sites More sharing options...
qsek Posted April 9, 2012 Share Posted April 9, 2012 Hallo auch. Well in this case i expierienced a similar behaviour. It depends how your commands are sent. For example telnet sends a char immediately when i type it, and your payload function get called as soon there is something recieved, which, in this case, can always only be one char.I dont know how NetCat behaves, maybe it adds some @CR @LF chars behind the command and therefore never gets matched.Anyway you should add some stop char on which the server recognises the end of a command. So until this char is not recieved you fill up a temp buffer variable with the letters you send, and if the stop char is recieved, you execute the payload function with the whole buffer, which should now hold the command.I can't get either the TCPSend Command OR the _Payload function to work.That was not a helpful problem description. "This doesnt work" can be a lot of things. In this case i assumed you didnt get anything at all. Otherwise, so i thought, you would have explained this wiered behavoiur in the first place. Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite Link to comment Share on other sites More sharing options...
twiztedshane Posted April 9, 2012 Author Share Posted April 9, 2012 Netcat is basically Telnet on steroids.. ~_~ Lol, i'm suprised you don't know about it. :| To my knowledge, netcat doesn't include any other characters (especially not abitary.. if it did, it would show up on debug). Maybe i should try a different approach to the problem.. and i don't know how to put up a buffer like you said, an example with comments would be appreciated. (: One last question, how come you're the only person who seems to answer questions around here.. O.O Have an awesome day(: Link to comment Share on other sites More sharing options...
qsek Posted April 9, 2012 Share Posted April 9, 2012 There are lots of examples in the Examples Forum. A search for the terms "tcprecv server client" will get you some:I dont know why im the only one. I hope its because the other people feel that theres not much to add and that my help is sufficient for you twiztedshane 1 Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite 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