You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TCPStartup() ; Start the TCP service.
; Register OnAutoItExit to be called when the script is closed.
OnAutoItExitRegister("OnAutoItExit")
If Not MyTCP_Server($sIPAddress, $iPort) Then Exit
EndFunc
Func MyTCP_Server($sIPAddress, $iPort)
; 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
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 & @CRLF & _WinAPI_GetErrorMessage($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 & @CRLF & _WinAPI_GetErrorMessage($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.
ConsoleWrite($sReceived)
; 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
Func _Main()
$hThread = _AuThread_StartThread("_StreamData")
EndFunc
While 1
Sleep(100)
WEnd
Func Tab1Change()
EndFunc
The text was updated successfully, but these errors were encountered:
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.16.1
Author: myName
Script Function:
Template AutoIt script.
#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIError.au3>
#include 'authread.au3'
Opt("GUIOnEventMode", 1)
Global $sIPAddress = "127.0.0.1" ; This IP Address only works for testing on your own computer.
Global $iPort = 23456 ; Port used for the connection.
_AuThread_Startup()
;_GUI()
;_StreamData()
_Main()
Func _GUI()
$Form1 = GUICreate("Form1", 1477, 385, 216, 214)
$Connect = GUICtrlCreateButton("Connect", 1400, 8, 75, 21)
$Tab1 = GUICtrlCreateTab(8, 32, 1465, 329)
GUICtrlSetOnEvent(-1, "Tab1Change")
$TabSheet1 = GUICtrlCreateTabItem("Terminal")
$TabSheet2 = GUICtrlCreateTabItem("Storico")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
EndFunc
Func _StreamData()
If Not MyTCP_Server($sIPAddress, $iPort) Then Exit
EndFunc
Func MyTCP_Server($sIPAddress, $iPort)
EndFunc ;==>MyTCP_Server
Func OnAutoItExit()
TCPShutdown() ; Close the TCP service.
EndFunc ;==>OnAutoItExit
Func _Main()
EndFunc
While 1
Sleep(100)
WEnd
Func Tab1Change()
EndFunc
The text was updated successfully, but these errors were encountered: