Suzuran Posted April 30, 2007 Posted April 30, 2007 (edited) I didn't understand a few things about TCP...here's the code with questions in the brackets. Global $MainSocket = -1 Global $ConnectedSocket = -1 ;(what is with this variable and why is it "-1" like the $MainSocket? ) Local $MaxConnection = 1; Maximum Amount Of Concurrent Connections Local $MaxLength = 512; Maximum Length Of String Local $Port = 1000; Port Number Local $Server = @IPAddress1; Server IpAddress TCPStartup() $MainSocket = TCPListen($Server, $Port) If $MainSocket = -1 Then Exit MsgBox(16, "Error", "Unable to intialize socket.") ; (Well, $MainSocket is already -1 because we ;just declared it like that...) While 1 $Data = TCPRecv($ConnectedSocket, $MaxLength) ; ( preety confuzed) If $Data = "~bye" Then MsgBox(16, "Session Ended", "Connection Terminated.") Exit ElseIf $Data <> "" Then ; Unconditional Receive MsgBox(0, "Received Packet", $Data) EndIf If $ConnectedSocket = -1 Then $ConnectedSocket = TCPAccept($MainSocket) If $ConnectedSocket <> -1 Then ; Someone Connected TCPSend($ConnectedSocket, "Connected!") EndIf EndIf WEnd Func OnAutoItExit() If $ConnectedSocket <> - 1 Then TCPSend($ConnectedSocket, "~bye") TCPCloseSocket($ConnectedSocket) EndIf If $MainSocket <> -1 Then TCPCloseSocket($MainSocket) TCPShutdown() EndFunc;==>OnAutoItExit The help in AutoIt isn't very good on TCP for begginers like me... Edited April 30, 2007 by Suzuran
Suzuran Posted April 30, 2007 Author Posted April 30, 2007 There is a "TCPAccept Loop" missing to accept connections on the $MainSocket...I don't think anything's missing...I got that exemple from here:http://www.autoitscript.com/forum/index.ph...c=20589&hl=.
Suzuran Posted April 30, 2007 Author Posted April 30, 2007 Flawed? I can't belive I spent 30 minutes to decipher it...and still confused on how AutoIt works with TCP.
Shevilie Posted April 30, 2007 Posted April 30, 2007 Suzuran.. if you need more info theres a lovely thread here Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit
birdofprey Posted May 1, 2007 Posted May 1, 2007 The foundation you need before using TCP is generally knowing how to script in AutoIt... once you have a good foundation...TCP is like this... (Single connection for now)SERVER- TCPStartup() always... to tell the TCP Gods you are coming...- TCPListen() on public IP of this PC .. returns a listening socket handle- BIG FOREVER LOOP--- little loop around TCPAccept( listening socket here ) until successful ... returns a connected socket handle------ return success then exitloop--- little loop TCPRecv( connected socket here )/TCPSend( connected socket here )------ to get data if the is any incoming... and send data if there is any to send------ if TCPRecv() or TCPSend() fails (@error) then exitloop (go back) to TCPAccept() and wait for another...-CLIENT- TCPStartup() always... to tell the TCP Gods you are coming...- TCPConnect() hopefully successful ... returns a connected socket handle- little loop TCPRecv( connected socket here )/TCPSend( connected socket here )--- to get data if the is any incoming... and send data if there is any to send--- if TCPRecv() or TCPSend() fails (@error) then exit or try to connect again (BIG FOREVER LOOP around this)Lar.Thank you very much Larry. Finally !
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