Jump to content

Run function without interrupting execution(or equivalent)?


Recommended Posts

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 = 0

TCPStartup()

$bleop = TCPListen("192.168.1.12", 7001, 100)

Do

Do

If $bleop = -1 Then

$a = 0

Else

$bleopt = TCPAccept($bleop)

If $bleopt <> -1 Then $a = 1

EndIf

Until $a = 1

If $bleopt >= 0 Then

TCPSend($bleopt, "Hello! Welcome to Benzrf's experimental server-type program." & @CRLF)

$rtddd = 0

Do

$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)

EndIf

Until $a = 0

$rf = $asr

$asdr = StringSplit($rf, " ")

$rfr = $asdr[1]

Switch $rfr

Case "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)

EndSwitch

Until $rtddd = 1

TCPCloseSocket($bleopt)

$gg = 1

Else

$gg = 0

EndIf

Until $gg = 1

TCPShutdown()

Exit

If 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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...