Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for me not work whats wrong ? #1

Open
faustf opened this issue Aug 10, 2023 · 0 comments
Open

for me not work whats wrong ? #1

faustf opened this issue Aug 10, 2023 · 0 comments

Comments

@faustf
Copy link

faustf commented Aug 10, 2023

#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)

GUICtrlSetOnEvent($Connect,_Main())

EndFunc

Func _StreamData()

  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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant