Jump to content

GUI freeze


 Share

Recommended Posts

I have this code here, it sort of works but whenever i try to close it it takes a couple of clicks and it seems like its freezing up on me for some reason

Not sure what is causing that.

#include <GUIConstantsEx.au3>

$ip = "75.150.216.162"
$port = 4099

$online2 = "ðECP ð"

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 120, 39, 376, 307)
$Label1 = GUICtrlCreateLabel("Label1", 16, 8, 80, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    TCPStartup()
    $socket = TCPConnect($ip, $port)
    TCPSend ( $socket, "ðLON123 123 0.42 100.100.100.100ð" )
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
    $recv = TCPRecv ($socket, 5000 )
    If $recv = $online2 Then
        GUICtrlSetData($Label1,"Server Online")
        GUICtrlSetBkColor($Label1, 0x00FF00)
    Else
        GUICtrlSetData($Label1,"Server Offline")
        GUICtrlSetBkColor($Label1, 0xFF0000)
    EndIf
    Sleep(100)
    TCPShutdown()
WEnd
Link to comment
Share on other sites

I'm a newb where it comes to TCP but it seems like there is no need to leave TCPStartup, TCPConnect, and TCPShutdown in your loop (for one thing)...

#include <GUIConstantsEx.au3>

$ip = "75.150.216.162"
$port = 4099

$online2 = "ðECP ð"

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 120, 39, 376, 307)
$Label1 = GUICtrlCreateLabel("Label1", 16, 8, 80, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

TCPStartup(); changed line
$socket = TCPConnect($ip, $port); changed line
While 1
    TCPSend ( $socket, "ðLON123 123 0.42 100.100.100.100ð" )
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
    $recv = TCPRecv ($socket, 5000 )
    If $recv = $online2 Then
        GUICtrlSetData($Label1,"Server Online")
        GUICtrlSetBkColor($Label1, 0x00FF00)
    Else
        GUICtrlSetData($Label1,"Server Offline")
        GUICtrlSetBkColor($Label1, 0xFF0000)
    EndIf
    Sleep(100)
WEnd
TCPShutdown(); changed line

Das Häschen benutzt Radar.

Link to comment
Share on other sites

Even better:

#include <GUIConstantsEx.au3>

$ip = "75.150.216.162"
$port = 4099
$online2 = "?ECP ?"
Global $start = TimerInit()

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 120, 39, 376, 307)
$Label1 = GUICtrlCreateLabel("Label1", 16, 8, 80, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

TCPStartup(); changed line
$socket = TCPConnect($ip, $port); changed line

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Exit
 EndSwitch

 If TimerDiff($start) > 1000 Then ; send/receive TCP once a second
    TCPSend ( $socket, "?LON123 123 0.42 100.100.100.100?" )
    $recv = TCPRecv ($socket, 5000 )
    If $recv = $online2 Then
        GUICtrlSetData($Label1,"Server Online")
        GUICtrlSetBkColor($Label1, 0x00FF00)
    Else
        GUICtrlSetData($Label1,"Server Offline")
        GUICtrlSetBkColor($Label1, 0xFF0000)
    EndIf
    $start = TimerInit()
 EndIf
WEnd

TCPShutdown(); changed line
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...