#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** HotKeySet("{ESC}", "Terminate");ESC to exit $ConnectedSocket = -1 TCPStartup() $counter = 0 While 1 $counter = $counter + 1 $text = "Transmission #" & $counter TCPSend($ConnectedSocket, StringToBinary($text, 4)) If @error Then ConsoleWrite("Sending failed: " & $text & @CRLF) ;try to reconnect everytime we notice the connection is lost $ConnectedSocket = TCPConnect("127.0.0.1", 33891) If $ConnectedSocket <> -1 And $ConnectedSocket <> 0 And @error = 0 Then;connection OK ConsoleWrite("Reconnect OK" & @CRLF) TCPSend($ConnectedSocket, StringToBinary($text, 4));send again If @error = 0 Then ConsoleWrite("ReSending OK: " & $text & @CRLF) Else ConsoleWrite("ReSending failed: " & $text & @CRLF) EndIf Else ConsoleWrite("Reconnect failed" & @CRLF) EndIf Else ConsoleWrite("Sending OK: " & $text & @CRLF) EndIf Sleep(1000) WEnd Func Terminate() ConsoleWrite("Shutting down" & @CRLF) TCPSend($ConnectedSocket, StringToBinary("", 4));say goodbye if possible TCPCloseSocket($ConnectedSocket) TCPShutdown() Exit EndFunc ;==>Terminate