Advertisement
Guest User

Server

a guest
Apr 28th, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.40 KB | None | 0 0
  1. TCPStartup()
  2.  
  3. OnAutoItExitRegister('_exit')
  4.  
  5. $tl = TCPListen('0.0.0.0', 1234)
  6. If @error Then Exit MsgBox(16, 'Server error', 'TCPListen @error = ' & @error)
  7.  
  8. Opt('GUIOnEventMode', 1)
  9. #Region ### START Koda GUI section ### Form=
  10. GUICreate("Server", 260, 74, 192, 124)
  11. GUICtrlCreateLabel("Client connected?", 8, 8, 90, 17)
  12. $Label1 = GUICtrlCreateLabel("NO", 104, 8, 36, 17)
  13. GUICtrlCreateButton("Close connection", 39, 40, 91, 25)
  14. GUICtrlSetOnEvent(-1, 'close')
  15. GUICtrlCreateButton("Exit", 147, 40, 75, 25)
  16. GUICtrlSetOnEvent(-1, '__exit')
  17. GUISetState(@SW_SHOW)
  18. #EndRegion ### END Koda GUI section ###
  19.  
  20. While 1
  21.     Do
  22.         $ta = TCPAccept($tl)
  23.     Until $ta <> -1
  24.     GUICtrlSetData($Label1, 'YES')
  25.     $ti = TimerInit()
  26.     While 1
  27.         If $ta = -1 Then ContinueLoop 2
  28.  
  29.         TCPRecv($ta, 1500)
  30.         If @error > 0 Then
  31.             closed('TCPRecv', @error)
  32.             ContinueLoop 2
  33.         EndIf
  34.  
  35.         If $ta = -1 Then ContinueLoop 2
  36.         If TimerDiff($ti) >= 100 Then
  37.  
  38.             TCPSend($ta, 'Testing...' & @CRLF)
  39.             If @error > 0 Then
  40.                 closed('TCPSend', @error)
  41.                 ContinueLoop 2
  42.             EndIf
  43.  
  44.             $ti = TimerInit()
  45.         EndIf
  46.     WEnd
  47. WEnd
  48.  
  49. Func _exit()
  50.     TCPShutdown()
  51. EndFunc
  52.  
  53. Func __exit()
  54.     Exit
  55. EndFunc
  56.  
  57. Func closed($f, $e)
  58.     MsgBox(0, 'Server', $f & ', connection closed, @error = ' & $e)
  59.     TCPCloseSocket($ta)
  60.     GUICtrlSetData($Label1, 'NO')
  61. EndFunc
  62.  
  63. Func close()
  64.     TCPCloseSocket($ta)
  65.     GUICtrlSetData($Label1, 'NO')
  66.     $ta = -1
  67. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement