Jump to content
Sign in to follow this  

TCP event handling or interrupt handling

Recommended Posts


Hi I am a newbie in AutoIt,

Currently i am using a TCP/IP to control a PC.

E.g When a computer receive specific Command from TCP/IP, the Auto-IT will take over the window and perform some operation.

$sock = TCPAccept($listen)

While ($sock > -1)

$sData = TCPRecv($iSocket, $iBytes)

; Perform some operation with sData


1. While AutoIt is in the middle of operation such as controling the deskstop and I want to terminate the operation through TCP/IP communication.

2. I want to terminate the AutoIt operation if the TCP communication is broken

The only idea that come through my mind was using pooling, but not sure is this the correct way to do thing.

$TimeOut = 1 ; Pool the socket for every one second

while (1)

;WindowName will prompt when the process completed

if (WinWait($WindowName,"",$TimeOut) == 0) Then

if ($sock > -1) then exit





Share this post

Link to post
Share on other sites

Global $NoTCP = 1
HotKeySet("{F1}", "FreezeTCP")
...farther in the script...
If $NoTCP = -1 Then TCPRecv($Socket, $Length)
If @Error And $NoTCP = 1 Then $LostConnection
Func FreezeTCP()
$NoTCP *= -1

Proof of concept. View my TCP Thread.

Basically If $NoTCP = 1 Then TCPRecv will be operated. Else It Won't. If TCPRecv returns that you had a failed socket, and $NoTCP = 1, then it will terminate the connection. FreezeTCP basically just flips $NoTCP between -1 and 1. Pressing F1 would freeze communication - but not continue to listen to the stack.

So...some pseudo explaination. Sorry - I'm not good at explaining TCP. I've just spent a long time using it.


Edit : nfwu made a priority queue to handle the packet pool/stream - whatever you'd like to call it. Below is a link to my Optimized TCP Generic Update 1. It contains the Queue.


Edited by AutoIt Smith

Share this post

Link to post
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
Sign in to follow this