themax90 Posted January 21, 2006 Share Posted January 21, 2006 (edited) I've had alot of requests for TCP information and examples, as well as UDP, but just in general TCP. So, too refrain from reasking questions and automated responses I have made a collection of my posted scripts and examples, and will be updating with a FAQ, tutorials, and other things of that sort soon.AutoIt-ITS Database Editor - Recommended for Secure ServersThe project AutoIt ITS is dead and all files can be found here : http://www.autoitscript.com/forum/index.php?showtopic=57470ToDo List:None.Here is some rather "Technical" information on TCP : Click HereExamples:TCP Made Easy:This can help you understand return values, and has everything on the TCP structure documented with a working example of Client/Server. TCPStartServer is highly recommended to use.AdminDB:A type of TCP Server that will store variables in memory allowing remote access and updating of more advanced type servers. A preset administrative password (if obfuscated) will make stealing ANY information in it near impossible. This server is used to store ITS Server data in realtime however the updated version is not released for security purposes. Converses in Hex.Remote Server *NEW*:Newest version support's almost ALL of AutoIt's functionality. Recommended for developer use only.Remote Server *OLD*:Older version of a "Remote" Server which has tons of nested pre-built functions. Recommended for home use.Server Communicator:Great for learning Syntax of other protocols such as POP3, SMTP, and if adapted correctly MySQL.Optimized TCP Generic Server:You can use this as just a BASIC background to making a server. All the code is there, and should be fully functional. Wrap your code around it and you have your own server! Highly Recommended. Update 1TCP Client Example:Global $MainSocket Local $MaxLength = 512; Maximum Length Of Text Local $Port = 1000; Port Number Local $Server = @IPAddress1; Server IpAddress TCPStartup() $MainSocket = TCPConnect($Server, $Port) If $MainSocket = -1 Then Exit MsgBox(16, "Error", "Unable to connect.") While 1 $Data = TCPRecv($MainSocket, $MaxLength) If $Data = "~bye" Then MsgBox(16, "Session Ended", "Connection Terminated.") Exit ElseIf $Data <> "" Then ; Unconditional Receive MsgBox(0, "Received Packet", $Data) EndIf WEnd Func OnAutoItExit() If $MainSocket <> - 1 Then TCPSend($MainSocket, "~bye") TCPCloseSocket($MainSocket) EndIf TCPShutdown() EndFunc;==>OnAutoItExitTCP Server Example:Global $MainSocket = -1 Global $ConnectedSocket = -1 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.") While 1 $Data = TCPRecv($ConnectedSocket, $MaxLength) 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;==>OnAutoItExitYou can also check my fileman at the below address for examples and random scripts I make. Please note : If a forum post is out of date, check the file man. All scripts are in there, however some may not be updated to work in the current release or beta.http://www.autoitscript.com/fileman/users/AutoIt%20Smith/AutoIt SmithUpdated July 27th, 2006 Edited November 18, 2007 by AutoIt Smith Link to comment Share on other sites More sharing options...
greenmachine Posted January 21, 2006 Share Posted January 21, 2006 (edited) Remote Server *NEW*:Newest version support's almost ALL of AutoIt's functionality ONLY if AutoIt is installed on host computer. May also hardcode the AutoIt.exe using FileInstall for users without AutoIt installed primarily. Recommended for developer use only.When you compile a script, such as the server, AutoIt writes all the built-in functions into the exe. Therefore, when you run a command using @Autoitexe and /Autoit3executeline, you're running it from the server's compiled exe. In this case, you do not need to have AutoIt installed.Edit - Even with AutoIt installed, if you compile a script and run it, it is simply running from that compiled script. Check the Task Manager when you run a compiled script - the task will be "name of the script".exe. Edited January 21, 2006 by greenmachine Link to comment Share on other sites More sharing options...
themax90 Posted January 21, 2006 Author Share Posted January 21, 2006 Thank you, I edited that. I was under a false impression. Link to comment Share on other sites More sharing options...
greenmachine Posted January 21, 2006 Share Posted January 21, 2006 (edited) I'm sure it's a common mistake. The only time you need the actual AutoIt exe is when you're running a script (au3), or when you're running an encrypted script (a3x) and you're not using another compiled script to do so. On a more positive note, instead of just pointing out errors I will say this: these scripts are very handy. Thanks for making them, they really helped me get a basis of understanding TCP functions. Edited January 21, 2006 by greenmachine Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 22, 2006 Moderators Share Posted January 22, 2006 Nice work Smith! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
themax90 Posted January 22, 2006 Author Share Posted January 22, 2006 I was figuring this could possibly become a sticky so all these threads and topics don't get started from simple TCP errors. Link to comment Share on other sites More sharing options...
themax90 Posted February 2, 2006 Author Share Posted February 2, 2006 I really wish this could become a sticky because there's been five or six posts in the past two weeks, this could help some people out and you can just redirect them to it. Link to comment Share on other sites More sharing options...
greenmachine Posted February 2, 2006 Share Posted February 2, 2006 You could add a link to this post in your sig (you have plenty of space left). Just be like: FOR ANYTHING TCP, GO HERE: (link) Link to comment Share on other sites More sharing options...
themax90 Posted February 19, 2006 Author Share Posted February 19, 2006 Email!!! Recently I have been researching and developing Email technologies. All that remains to make a true pop3/smtp client is having the strings sorted according to the server. A very simple task. So here is an example script demonstrating Pop3 protocol. expandcollapse popupGlobal $Recv Global $Server = "mail.comcast.net" Global $ServerIp = TCPNameToIP($Server) TCPStartup() Global $MainSocket = TCPConnect($ServerIp, 110) If $MainSocket = -1 Then Exit MsgBox(0, "Failure", "Failed to contact server.") Global $GUI = GUICreate("Pop Speak Testing", 180, 300) Global $PopSpeak = GUICtrlCreateInput("", 10, 10, 160, 20) Global $Send = GUICtrlCreateButton("Send", 90, 40, 80, 15) Global $Help = GUICtrlCreateButton("Help", 10, 40, 75, 15) Global $History = GUICtrlCreateEdit("Contacting " & $Server & " > " & $ServerIp, 10, 65, 160, 225, 0x00200000) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = -3 Exit Case $msg = $Send TCPSend2($MainSocket, GUICtrlRead($PopSpeak) & @CRLF) Case $msg = $Help TCPSend2($MainSocket, "help" & @CRLF) EndSelect $Recv = TCPRecv($MainSocket, 512) Select Case $Recv <> "" FileWriteLine("Log.txt", $Recv) GUICtrlSetData($History, GUICtrlRead($History) & @CRLF & "In: " & $Recv) Case Else ; There is no message. EndSelect WEnd Func OnAutoItExit() TCPSend($MainSocket, "quit" & @CRLF) TCPCloseSocket($MainSocket) TCPShutdown() EndFunc Func TCPSend2($Socket, $Text) TCPSend($Socket, $Text) FileWriteLine("Log.txt", $Text) GUICtrlSetData($History, GUICtrlRead($History) & @CRLF & "Out: " & $Text) GUICtrlSetData($PopSpeak, "") EndFunc NOTES ON POP3 INTERFACE For any TCP interfacing using AutoIt you must send the text followed by a clean line. Example : TCPSend($Socket, $Data & @CRLF) Usually getting an IpAddress using TCPNameToIP($Name) will sort out most connection issues. Do not login using a TCP program made by AutoIt and abruptly close the connection without first sending quit, otherwise AutoIt will not be allowed to connect on the Pop3 socket until your next reboot. Hope you enjoy and people can make things out of my notes. - AutoIt Smith Link to comment Share on other sites More sharing options...
nfwu Posted February 22, 2006 Share Posted February 22, 2006 (edited) I think some people may also find this useful:http://www.networksorcery.com/enp/topic/ipsuite.htmJust in case anyone asks me what are layers, here they are:Layer 7: Application : Where the actual Application is (i.e. your autoit app)Layer 6: Presentation: Responsible for data translation and code formatting Layer 5: Session :Setting up, managing, then tearing down sessions (NFS, SQL, RPC, X Window, ASP, DNA SCP)Layer 4: Transport : Reassembles data into a data stream (TCP, UDP: Working wirh IP addresses)Layer 3: Network : Manages device addressing, location of device on network and determines the best way to move data (Routers: Working with MAC addresses [the one that is burnt into your network card]) {DATA PACKETS}Layer 2: Data Link : Error notification, network topology, and flow control. Ensure devivered to proper lan using Physical(MAC) addresses (Switches, Bridges) {DATA FRAMES}Layer 1: Physical : Sends 1s and 0s (Hubs) Edited February 22, 2006 by nfwu TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
themax90 Posted February 23, 2006 Author Share Posted February 23, 2006 Questions that are of decent quality, please before contact see if you cannot answer it from here:http://www.autoitscript.com/forum/index.php?showtopic=22080- AutoIt Smith Link to comment Share on other sites More sharing options...
nfwu Posted February 24, 2006 Share Posted February 24, 2006 (edited) Not my first time doing Networking code, but it's my first time in AutoIt. 1) Are the TCP/UDP functions Blocking (i.e. They wait for data before returning) or are they Non-Blocking (i.e. They check the stream and return nothing if no data, otherewise, they return the data) 2) If the TCP/UDP functions are blocking, is there a timeout? (I think Opt("TCPTimeout", 100) is what i'm looking for) 3) How is the TCP/UDP data returned? As a string or an array? Edited February 24, 2006 by nfwu TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
greenmachine Posted February 24, 2006 Share Posted February 24, 2006 I believe I can answer those: 1. Non-blocking: try playing with TCPRecv especially. It definitely returns an empty string it no data was sent. 2. TCPTimeout is it indeed. 3. The data is returned as a string. Link to comment Share on other sites More sharing options...
nfwu Posted February 24, 2006 Share Posted February 24, 2006 Ifyou want to make a Packet Detector / Packet Sniffler, you may find http://www.winpcap.org/ useful.#) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
themax90 Posted February 24, 2006 Author Share Posted February 24, 2006 Yes, but for other's it would be harder. I am trying to make one in native autoit. Link to comment Share on other sites More sharing options...
GrungeRocker Posted February 28, 2006 Share Posted February 28, 2006 is it possible to send other files instead of text?e.g.: an *.exe file [font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font] Link to comment Share on other sites More sharing options...
greenmachine Posted March 1, 2006 Share Posted March 1, 2006 is it possible to send other files instead of text?e.g.: an *.exe fileMost definitely. Larry took care of this issue in this thread: http://www.autoitscript.com/forum/index.php?showtopic=16328 Link to comment Share on other sites More sharing options...
themax90 Posted March 1, 2006 Author Share Posted March 1, 2006 (edited) I am currently doing something which I have never thought I would do. I am releasing AdminDB.Go here to find what it is :http://www.autoitscript.com/forum/index.php?showtopic=22371I never thought I would release this because it was the secret weapon to hide passwords in my server system, but I see no folly as the password can be a long random string no one can guess, and soon I will make my own encryption system, making it uneasy to break into. Edited July 27, 2006 by AutoIt Smith Link to comment Share on other sites More sharing options...
NegativeNrG Posted March 1, 2006 Share Posted March 1, 2006 Autoit smith, in the TCP Server Example, how do you allow more connections? i've looked through the code, and i see the variable $maxconnection, but it isnt never been used. [size=20]My File Upload[/size]Register at my site and upload. Link to comment Share on other sites More sharing options...
themax90 Posted March 1, 2006 Author Share Posted March 1, 2006 It's set at the top to 100, just change that and you change the Maximum Connections. 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