benzrf Posted April 6, 2009 Share Posted April 6, 2009 I created a script that listens for connections on port 7001, and when it finds one, it connects and runs the next part of the script(which allows the client to enter various commands that the script understands). What I want to do is have it listen for connections, and when it finds one, runs a function or separate EXE to take care of the connection. However, I can't seem to pass the socket ID to the separate EXE, and functions interrupt the execution of the main program, which prevents it from listening for a new connection.How do I solve this?If it helps, here's the code(I have a tendency to give my variables bizarre and wacky names, please do not ask any questions, it's a bad habit):CODE#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.0.0 Author: Benzrf Script Function: Template AutoIt script.#ce ----------------------------------------------------------------------------; Script Start - Add your code below here#include <iNet.au3>$gg = 0$a = 0TCPStartup()$bleop = TCPListen("192.168.1.12", 7001, 100)DoDo If $bleop = -1 Then $a = 0 Else $bleopt = TCPAccept($bleop) If $bleopt <> -1 Then $a = 1 EndIfUntil $a = 1If $bleopt >= 0 ThenTCPSend($bleopt, "Hello! Welcome to Benzrf's experimental server-type program." & @CRLF)$rtddd = 0Do$asr = ""Do $rfd = TCPRecv($bleopt, 100000) $rfr = String($rfd) If $rfr = "" Then $a = 1 Else If $rfr = @CRLF Then $a = 0 Else $asr = $asr & $rfr EndIf ;MsgBox(0, "", $rf) EndIfUntil $a = 0$rf = $asr$asdr = StringSplit($rf, " ")$rfr = $asdr[1]Switch $rfrCase "TIME" TCPSend($bleopt, @CRLF & "The hour is " & @HOUR & "." & @CRLF & @CRLF)Case "DNS" $vasd = TCPNameToIP(StringMid($rf, 5)) If $vasd = "" Then $vasd = @CRLF & "The hostname could not be found." & @CRLF & @CRLF Else $vasd = @CRLF & "The IP of " & StringMid($rf, 5) & " is " & $vasd & "." & @CRLF & @CRLF EndIf TCPSend($bleopt, $vasd)Case "QUIT" $rtddd = 1 TCPSend($bleopt, @CRLF & "Exit in four seconds. Goodbye." & @CRLF & @CRLF) Sleep(4000)Case "ABOUT" TCPSend($bleopt, @CRLF & "Experimental Server-Type Program ©opyright Benzrf 2009." & @CRLF & @CRLF)Case Else TCPSend($bleopt, @CRLF & "Invalid command " & $rfr & "." & @CRLF & @CRLF)EndSwitchUntil $rtddd = 1TCPCloseSocket($bleopt)$gg = 1Else$gg = 0EndIfUntil $gg = 1TCPShutdown()ExitIf you notice unnecessary code I can get rid of, or redundancies, please do not point them out, I just want to know how to run my lower bit of code separately from my upper half. Link to comment Share on other sites More sharing options...
benzrf Posted April 6, 2009 Author Share Posted April 6, 2009 bump Link to comment Share on other sites More sharing options...
benzrf Posted April 6, 2009 Author Share Posted April 6, 2009 bump Link to comment Share on other sites More sharing options...
monoceres Posted April 6, 2009 Share Posted April 6, 2009 Well you can't just pass sockets you receive in your process and expect them to work in a totally different process. In most languages you solve this with multi-threading, but since that's not an option in autoit you'll have to do something different. Maybe store the sockets in an array and have an adlib function loop through all the sockets and act on them? Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
BinaryBrother Posted April 6, 2009 Share Posted April 6, 2009 I could be wrong, but I'm pretty sure that AutoIt only supports one instance of TCP functions. One idea would be to run multiple instances of the same script, but I've even found bugs doing that... SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
benzrf Posted April 7, 2009 Author Share Posted April 7, 2009 monoceres, I'll try your idea. Let you know if it works! Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 7, 2009 Share Posted April 7, 2009 In all technicality, yes you can pass socket handles between applications. Trying to pass AutoIt's socket handle is a different matter though. 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