Jump to content
Sign in to follow this  
Der_Andi

OnExitFunc not executed, when script exits

Recommended Posts

Der_Andi

Hi,

first i start the listen-script:

TCPStartup()
$socket = TCPListen(@IPAddress1, 33333)

Do
    $conn = TCPAccept($socket)
    Sleep(500)
Until $conn <> -1

Do
    $recv = TCPRecv($socket, 512)
    Sleep(1000)
Until $recv <> ""

MsgBox(0, "", $recv)
oÝ÷ Ø2¢çÇקvÌ!zv¬¶¸§++yÇ¢½çp'!Éèµé­§$ázz-zjmÊËkx"²Ç§µ¼­ëÛ®*mjëh×6
Opt("OnExitFunc", "_quit")
TCPStartup()
$socket = TCPConnect(@IPAddress1, 33333)

Sleep(2000)
Exit

Func _quit()    ;defined as OnExitFunc
    TCPSend($socket, "bye")
    TCPShutdown()
EndFunc

The "bye" is not being sent.

I'm testing these scripts on one computer.

Some ideas? After 30 minutes, i gave up... :shocked:

Share this post


Link to post
Share on other sites
MrCreatoR

If you want to check if the function is executed, just out MsgBox at start of that function, and you will see if this function is started when exit, if so, then the problem is in TCPSend($socket, "bye").


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
jvanegmond

TCPStartup()

Dim $ConnectedSocket = -1

$Socket = TCPListen(@IPAddress1,33333)

While 1
    $NewSocket = TCPAccept($Socket)
    If $NewSocket >= 0 Then
        $ConnectedSocket = $NewSocket
    EndIf
    If $ConnectedSocket <> -1 Then
        $Data = TCPRecv($ConnectedSocket,1024)
        If $Data <> "" Then ConsoleWrite($Data)
    EndIf
WEndoÝ÷ Ù8Z¶+0«Hjk¬x-¡Æ©¶êÞu«ZJÚÚ¥ÊØ^ìmn+]¡ë'¢Ü(®G¢¶«ß}÷lGb·öå¢[hu¬¢µÚ±¹bDájܲËkjxjëh×6TCPStartup()
$socket = TCPConnect(@IPAddress1, 33333)

TCPSend($socket,"test data" & @CRLF)
Sleep(2000)
_quit()
Exit

Func _quit()    ;defined as OnExitFunc
    TCPSend($socket,"bye")
    TCPShutdown()
EndFuncoÝ÷ Ù»­¶¬v¬jëh×6TCPStartup()
$socket = TCPConnect(@IPAddress1, 33333)

TCPSend($socket,"test data" & @CRLF)
Sleep(2000)
TCPSend($socket,"bye")
TCPShutdown()
Exit

Edited by Manadar

Share this post


Link to post
Share on other sites
martin

TCPStartup()

Dim $ConnectedSocket = -1

$Socket = TCPListen(@IPAddress1,33333)

While 1
    $NewSocket = TCPAccept($Socket)
    If $NewSocket >= 0 Then
        $ConnectedSocket = $NewSocket
    EndIf
    If $ConnectedSocket <> -1 Then
        $Data = TCPRecv($ConnectedSocket,1024)
        If $Data <> "" Then ConsoleWrite($Data)
    EndIf
WEndoÝ÷ Ù8Z¶+0«Hjk¬x-¡Æ©¶êÞu«ZJÚÚ¥ÊØ^ìmn+]¡ë'¢Ü(®G¢¶«ß}÷jëh×6TCPStartup()
$socket = TCPConnect(@IPAddress1, 33333)

TCPSend($socket,"test data" & @CRLF)
Sleep(2000)
_quit()
Exit

Func _quit()    ;defined as OnExitFunc
    TCPSend($socket,"bye")
    TCPShutdown()
EndFuncoÝ÷ Ù»­¶¬v¬jëh×6TCPStartup()
$socket = TCPConnect(@IPAddress1, 33333)

TCPSend($socket,"test data" & @CRLF)
Sleep(2000)
TCPSend($socket,"bye")
TCPShutdown()
Exit

What happens if you use 127.0.0.1 for the ip address instead of @IPAddress1?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Der_Andi

What happens if you use 127.0.0.1 for the ip address instead of @IPAddress1?

The same: nothing.

@MsCreatoR:

A MsgBox in the OnAutoItExit-Function is executed. But not the TCPSend().

This is either strange or a bug!

Background:

I want to create a client-like script that would run on a remote computer. When this computer goes down, the script sends a bye-message to the server-script on my computer.

I also had the idea to work with a keep-alive-signal. Every x seconds the client sends a signal. If the remote computer goes down, no more signal can be sent.

Share this post


Link to post
Share on other sites
MHz

The "bye" is not being sent.

I'm testing these scripts on one computer.

Some ideas? After 30 minutes, i gave up... :shocked:

Your script cannot continue into the OnAutoitExit function because your script has exited upon calling the OnAutoitExit function. You will still have use of the variables as they are still in memory and you can now use the @exitmethod as well as the @exitcode macro's. The OnAutoitExit function is for cleanup and not for continuation of code from the main script.

:(

Edited by MHz

Share this post


Link to post
Share on other sites
Der_Andi

...because your script has exited ...

That sounds logical. :shocked:

I thought, the OnAutoItExit-Function is executed before the actual Exit.

Edited by Der_Andi

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.