Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TCPStartup()
- OnAutoItExitRegister('_exit')
- $tl = TCPListen('0.0.0.0', 1234)
- If @error Then Exit MsgBox(16, 'Server error', 'TCPListen @error = ' & @error)
- Opt('GUIOnEventMode', 1)
- #Region ### START Koda GUI section ### Form=
- GUICreate("Server", 260, 74, 192, 124)
- GUICtrlCreateLabel("Client connected?", 8, 8, 90, 17)
- $Label1 = GUICtrlCreateLabel("NO", 104, 8, 36, 17)
- GUICtrlCreateButton("Close connection", 39, 40, 91, 25)
- GUICtrlSetOnEvent(-1, 'close')
- GUICtrlCreateButton("Exit", 147, 40, 75, 25)
- GUICtrlSetOnEvent(-1, '__exit')
- GUISetState(@SW_SHOW)
- #EndRegion ### END Koda GUI section ###
- While 1
- Do
- $ta = TCPAccept($tl)
- Until $ta <> -1
- GUICtrlSetData($Label1, 'YES')
- $ti = TimerInit()
- While 1
- If $ta = -1 Then ContinueLoop 2
- TCPRecv($ta, 1500)
- If @error > 0 Then
- closed('TCPRecv', @error)
- ContinueLoop 2
- EndIf
- If $ta = -1 Then ContinueLoop 2
- If TimerDiff($ti) >= 100 Then
- TCPSend($ta, 'Testing...' & @CRLF)
- If @error > 0 Then
- closed('TCPSend', @error)
- ContinueLoop 2
- EndIf
- $ti = TimerInit()
- EndIf
- WEnd
- WEnd
- Func _exit()
- TCPShutdown()
- EndFunc
- Func __exit()
- Exit
- EndFunc
- Func closed($f, $e)
- MsgBox(0, 'Server', $f & ', connection closed, @error = ' & $e)
- TCPCloseSocket($ta)
- GUICtrlSetData($Label1, 'NO')
- EndFunc
- Func close()
- TCPCloseSocket($ta)
- GUICtrlSetData($Label1, 'NO')
- $ta = -1
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement