Advertisement
Guest User

Client

a guest
Apr 28th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.38 KB | None | 0 0
  1. TCPStartup()
  2.  
  3. OnAutoItExitRegister('_exit')
  4. Global $connected, $tc
  5.  
  6. Opt('GUIOnEventMode', 1)
  7. #Region ### START Koda GUI section ### Form=
  8. GUICreate("Client", 246, 50, 194, 461)
  9. $Button1 = GUICtrlCreateButton("Connect", 33, 16, 75, 25)
  10. GUICtrlSetOnEvent(-1, 'connect')
  11. GUICtrlCreateButton("Exit", 137, 16, 75, 25)
  12. GUICtrlSetOnEvent(-1, '__exit')
  13. GUISetState(@SW_SHOW)
  14. #EndRegion ### END Koda GUI section ###
  15.  
  16. $ti = TimerInit()
  17. While 1
  18.     If $connected Then
  19.  
  20.         TCPRecv($tc, 1500)
  21.         If @error > 0 Then
  22.             closed('TCPRecv', @error)
  23.             ContinueLoop
  24.         EndIf
  25.  
  26.         If Not $connected Then ContinueLoop
  27.         If TimerDiff($ti) >= 100 Then
  28.  
  29.             TCPSend($tc, 'Testing...' & @CRLF)
  30.             If @error > 0 Then
  31.                 closed('TCPSend', @error)
  32.                 ContinueLoop
  33.             EndIf
  34.  
  35.             $ti = TimerInit()
  36.         EndIf
  37.     Else
  38.         Sleep(100)
  39.     EndIf
  40. WEnd
  41.  
  42. Func _exit()
  43.     TCPShutdown()
  44. EndFunc
  45.  
  46. Func __exit()
  47.     Exit
  48. EndFunc
  49.  
  50. Func connect()
  51.     If $connected Then
  52.         TCPCloseSocket($tc)
  53.         GUICtrlSetData($Button1, 'Connect')
  54.         $connected = 0
  55.         Return
  56.     EndIf
  57.  
  58.     $tc = TCPConnect('127.0.0.1', 1234)
  59.     If @error Then Return MsgBox(16, 'Client error', 'TCPConnect @error = ' & @error)
  60.     GUICtrlSetData($Button1, 'Disconnect')
  61.     $connected = 1
  62. EndFunc
  63.  
  64. Func closed($f, $e)
  65.     MsgBox(0, 'Client', $f & ', connection closed, @error = ' & $e)
  66.     TCPCloseSocket($tc)
  67.     GUICtrlSetData($Button1, 'Connect')
  68.     $connected = 0
  69. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement