d0n Posted July 16, 2009 Posted July 16, 2009 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
UberNuss Posted July 16, 2009 Posted July 16, 2009 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.
Zedna Posted July 16, 2009 Posted July 16, 2009 Even better: expandcollapse popup#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 Resources UDF ResourcesEx UDF AutoIt Forum Search
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now