Sign in to follow this  
Followers 0
GoogleDude

TCPConnect(), Sleep() While TrayGetMsg still lookin?

2 posts in this topic

#1 ·  Posted (edited)

I am trying to create a systray based app that is really small in that all it does is attempt to connect to a listening TCP port on a remote IP every few minutes and if for some reason it us unable to it displays a MSGBOX. But at the same same time it (every 60mins or so) attempting to connect to the port still look for $MSG (based on example in help for TraySetState() using TrayGetMsg() mode. My problem is that every. My systray has some TrayItems to open apps if wanted but in the backround periodically checking a servers tcp port status to make sure its open.

I searched for TCP Port Monitor on the forum for maybe an example but didnt really see much.

And all my samples are getting stuck in a loop of attempting to connect to the tcp port and thats all it iwill let me do. None of the other TrayItems including Exit will work. And since I am wanting to only attempt to connect every so often Im not sure where to have the Sleep() function at and not interfear with me being able click other TrayItems.

Make sense? I know I tend to ask questions that sound confusing than they really are.

Here is all I can come up with

Thanks for any help. Sorry if its confusing. Its basicly a TCP Port Monitor with some TrayItems that will Run() an EXE if clicked.

#Include <Constants.au3>
#NoTrayIcon
#AutoIt3Wrapper_Run_Debug_Mode=Y

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.


TCPStartUp()


$Settings = TrayCreateItem("Settings")
TrayCreateItem("")
$CheckOnLine = TrayCreateItem("Check If Server is Online")
TrayCreateItem("")
$OpenApp1 = TrayCreateItem("Open App1")
TrayCreateItem("")
$ExitTray = TrayCreateItem("Exit")

TraySetState()


While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            $IP = "192.168.1.123"
            $socket = TCPConnect( $IP, 3456 )
            If $socket = -1 Then 
                MsgBox(48,"Unable to Connect","Unable to connect to TCP Port on Server!")
            EndIf
        Case $msg = $CheckOnLine
            $IP = "192.168.1.123"
            $socket = TCPConnect( $IP, 3456 )
            If $socket = -1 Then 
                MsgBox(48,"Unable to Connect","Unable to connect to TCP Port on Server!")
            EndIf
        Case $msg = $ExitTray
            ExitLoop
    EndSelect
WEnd

Exit
Edited by GoogleDude

Share this post


Link to post
Share on other sites



I am trying to create a systray based app that is really small in that all it does is attempt to connect to a listening TCP port on a remote IP every few minutes and if for some reason it us unable to it displays a MSGBOX. But at the same same time it (every 60mins or so) attempting to connect to the port still look for $MSG (based on example in help for TraySetState() using TrayGetMsg() mode. My problem is that every. My systray has some TrayItems to open apps if wanted but in the backround periodically checking a servers tcp port status to make sure its open.

I searched for TCP Port Monitor on the forum for maybe an example but didnt really see much.

And all my samples are getting stuck in a loop of attempting to connect to the tcp port and thats all it iwill let me do. None of the other TrayItems including Exit will work. And since I am wanting to only attempt to connect every so often Im not sure where to have the Sleep() function at and not interfear with me being able click other TrayItems.

Make sense? I know I tend to ask questions that sound confusing than they really are.

Here is all I can come up with

Thanks for any help. Sorry if its confusing. Its basicly a TCP Port Monitor with some TrayItems that will Run() an EXE if clicked.

To start with, you can't mix event mode and a msg loop together (for Tray or GUI events). Try basing it on this:

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)   ; Default tray menu items (Script Paused/Exit) will not be shown.

; TCPStartUp()

$Settings = TrayCreateItem("Settings")
TrayItemSetOnEvent(-1, "_TrayItemHit")
TrayCreateItem("")
$CheckOnLine = TrayCreateItem("Check If Server is Online")
TrayItemSetOnEvent(-1, "_TrayItemHit")
TrayCreateItem("")
$OpenApp1 = TrayCreateItem("Open App1")
TrayItemSetOnEvent(-1, "_TrayItemHit")
TrayCreateItem("")
$ExitTray = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_TrayItemHit")
TraySetState()

While 1
    Sleep(20)
WEnd

Func _TrayItemHit()
    Local $TrayCtrlID = @TRAY_ID
    Switch $TrayCtrlID
        Case $Settings
            ConsoleWrite("Debug: Do Settings stuff..." & @LF)
        Case $CheckOnLine
            ConsoleWrite("Debug: Do CheckOnLine stuff..." & @LF)
        Case $OpenApp1
            ConsoleWrite("Debug: Do OpenApp1 stuff..." & @LF)
        Case $ExitTray
            Exit
    EndSwitch
EndFunc   ;==>_TrayItemHit

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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