sloppyprogrammer Posted July 21, 2009 Share Posted July 21, 2009 Hi! This is my script for a very simple server. It works very nice, and it took me about 15 min to make, so it's kinda sloppy... I've cleaned up the code somewhat, but if I've bothered, I could have made it much cleaner... I know this isn't advanced or anything, but since it's so well commented, if i may say so, I think that it may help out ppl who are new to networking in AutoIt. expandcollapse popupglobal $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 = "" ; ======================================================= ; TCPStartUp() ; Starts TCP services ; ======================================================= ; $MainSocket = TCPListen($l_IP, 65432, 100 ) ; start a listening socket If $MainSocket = -1 Then Exit ; if a socket can't be created, exit the server ; ======================================================= ; _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(500,120) ; make a beep (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. WEnd EndFunc ; ======================================================= ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ======================================================= ; func _payload($myPayload) ; starts the payload function. Switch $myPayload ; Check the contents of the last recived package. case "doSomething1" ; If the package contained the message "doSomething1" then ; ... ; Do something ; ... ; Do something ; ... ; Do something case "doSomething2" ; If the package contained the message "doSomething2" then ; ... ; Do something ; ... ; Do something ; ... ; Do something 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 ; ======================================================= ; Use it for whatever you want! Credit not needed, but would be nice! =) Cheers! - SloppyProgrammer [center]They say that there is only 10 kinds of people that understand binary code; those who do, and those who don't...[/center][center]Get it? :P[/center] Link to comment Share on other sites More sharing options...
playlet Posted July 21, 2009 Share Posted July 21, 2009 (edited) --- Edited August 18, 2016 by playlet Link to comment Share on other sites More sharing options...
sloppyprogrammer Posted July 21, 2009 Author Share Posted July 21, 2009 Removing ; ====================== was actually something I was thinking about, but when I'm bored, I put in useless crap like that into my scripts, and never take it out... Bad habit I suppose... - SloppyProgrammer [center]They say that there is only 10 kinds of people that understand binary code; those who do, and those who don't...[/center][center]Get it? :P[/center] Link to comment Share on other sites More sharing options...
twiztedshane Posted April 3, 2012 Share Posted April 3, 2012 It exits as soon as it is oppened.. :/ Link to comment Share on other sites More sharing options...
spudw2k Posted April 3, 2012 Share Posted April 3, 2012 (edited) It exits as soon as it is oppened.. :/twiztedshane,Welcome to the AutoIt forum. (sorry Melba32)It is preferred that users do not revive (post on) old threads unless you have a significant contribution (and I mean significant).You can see the "age" of a post right at the begging of it. (Posted 21 July 2009 - 03:03 PM) Most code posted years ago will not work due to AutoIt revisions.edit: corrected weird double quote Edited April 3, 2012 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
twiztedshane Posted April 3, 2012 Share Posted April 3, 2012 Oh, i'm awfully sorry about that. I didn't mean to cause any trouble. =/ 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