Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TCPStartup()
- OnAutoItExitRegister('_exit')
- Global $connected, $tc
- Opt('GUIOnEventMode', 1)
- #Region ### START Koda GUI section ### Form=
- GUICreate("Client", 246, 50, 194, 461)
- $Button1 = GUICtrlCreateButton("Connect", 33, 16, 75, 25)
- GUICtrlSetOnEvent(-1, 'connect')
- GUICtrlCreateButton("Exit", 137, 16, 75, 25)
- GUICtrlSetOnEvent(-1, '__exit')
- GUISetState(@SW_SHOW)
- #EndRegion ### END Koda GUI section ###
- $ti = TimerInit()
- While 1
- If $connected Then
- TCPRecv($tc, 1500)
- If @error > 0 Then
- closed('TCPRecv', @error)
- ContinueLoop
- EndIf
- If Not $connected Then ContinueLoop
- If TimerDiff($ti) >= 100 Then
- TCPSend($tc, 'Testing...' & @CRLF)
- If @error > 0 Then
- closed('TCPSend', @error)
- ContinueLoop
- EndIf
- $ti = TimerInit()
- EndIf
- Else
- Sleep(100)
- EndIf
- WEnd
- Func _exit()
- TCPShutdown()
- EndFunc
- Func __exit()
- Exit
- EndFunc
- Func connect()
- If $connected Then
- TCPCloseSocket($tc)
- GUICtrlSetData($Button1, 'Connect')
- $connected = 0
- Return
- EndIf
- $tc = TCPConnect('127.0.0.1', 1234)
- If @error Then Return MsgBox(16, 'Client error', 'TCPConnect @error = ' & @error)
- GUICtrlSetData($Button1, 'Disconnect')
- $connected = 1
- EndFunc
- Func closed($f, $e)
- MsgBox(0, 'Client', $f & ', connection closed, @error = ' & $e)
- TCPCloseSocket($tc)
- GUICtrlSetData($Button1, 'Connect')
- $connected = 0
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement