#include Example() Func Example() TCPStartup() ; Start the TCP service. ; Register OnAutoItExit to be called when the script is closed. OnAutoItExitRegister("OnAutoItExit") ; Assign Local variables the loopback IP Address and the Port. Local $sIPAddress = "192.168.0.79" ; This IP Address only works for testing on your own computer. Local $iPort = 33000 ; Port used for the connection. ; Assign a Local variable the socket and connect to a Listening socket with the IP Address and Port specified. Local $iSocket = TCPConnect($sIPAddress, $iPort) ; If an error occurred display the error code and return False. If @error Then ; The server is probably offline/port is not opened on the server. Local $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Could not connect, Error code: " & $iError) Return False Else MsgBox($MB_SYSTEMMODAL, "", "Connection successful") EndIf TCPSend($iSocket, "RU_01") sleep(100) TCPSend($iSocket, @CRLF) sleep(1000) MyTCP_Server($sIPAddress, $iPort) ; Close the socket. ; TCPCloseSocket($iSocket) EndFunc ;==>Example Func MyTCP_Server($sIPAddress, $iPort) msgbox(0,"gata","2") ; Assign a Local variable the socket and bind to the IP Address and Port specified with a maximum of 100 pending connexions. Local $iListenSocket = TCPListen($sIPAddress, $iPort, 100) Local $iError = 0 msgbox(0,"gata","2") If @error Then ; Someone is probably already listening on this IP Address and Port (script already running?). $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not listen, Error code: " & $iError) Return False EndIf ; Assign a Local variable to be used by the Client socket. Local $iSocket = 0 Do ; Wait for someone to connect (Unlimited). ; Accept incomming connexions if present (Socket to close when finished; one socket per client). $iSocket = TCPAccept($iListenSocket) ; If an error occurred display the error code and return False. If @error Then $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not accept the incoming connection, Error code: " & $iError) Return False EndIf If GUIGetMsg() = $GUI_EVENT_CLOSE Then Return False Until $iSocket <> -1 ;if different from -1 a client is connected. ; Close the Listening socket to allow afterward binds. TCPCloseSocket($iListenSocket) ; Assign a Local variable the data received. Local $sReceived = TCPRecv($iSocket, 2048) ;we're waiting for the string "tata" OR "toto" (example script TCPRecv): 4 bytes length. ; Notes: If you don't know how much length will be the data, ; use e.g: 2048 for maxlen parameter and call the function until the it returns nothing/error. ; Display the string received. MsgBox($MB_SYSTEMMODAL, "", "Server:" & @CRLF & "Received: " & $sReceived) ; Close the socket. TCPCloseSocket($iSocket) EndFunc ;==>MyTCP_Server Func OnAutoItExit() TCPShutdown() ; Close the TCP service. EndFunc ;==>OnAutoItExit