Jump to content
Sign in to follow this  
Guest AnTont

TCPSend and TCPRecv AU3Xtra.dll problems

Recommended Posts

Guest AnTont

I'm currently using TCL to send data to AutoIt.

The TCPRecv seem to wait for several request until it unblocks. The TCPSend

call only sends when the connection is closed. All the messages are queued up and are released on a close. I should be able to send a message from the TCL side and the AutoIt side should unblock and dequeue the message. The same with the Send side.

------------------------------------------------------------------------------------

PC side

-------------------------------------------------------------------------------------

;EXAMPLE SERVER CODE using AU3Xtra.DLL
;======================================
Global $WSABASEERR = 10000
Global $socket = 0
Global $str = ""
Dim $myarray[80]
Dim $themessage[80]

$myarray = "TEST--- Before TCPStartUp "

;Start the TCP abilities
;-----------------------
 msgBox(0,"Before TCPStartUp" & $myarray, "TCPStartUp" & $myarray)
$x = DLLCall( "C:\AU3Xtra.dll", "int", "TCPStartUp" )
If @error Or $x[0] = 0 Then

 $myarray = "TEST--- ERRORING Exiting TCPStartUp FAILED "
 msgBox(0,"TCPStartUp FAILED" & $myarray, "TCPStartUp FAILED" & $myarray)
 Exit
Endif

;Wait for a connection
;-----------------------
$myarray = "TEST--- Before TCPListen "
msgBox(0,"Before TCPListen" & $myarray, "TCPListen" & $myarray)
$x = DLLCall( "C:\AU3Xtra.dll", "int", "TCPListen",_
            "str", "10.6.8.90",_
            "int", 1025 )
If @error Then CleanUp(0)
$socket = $x[0]

;Wait to receive data. Loop until "quit" or "" is received,
;                      or disconnection.
;---------------------------------------------------------
$myarray = "TEST--- Before TCPRecv "
msgBox(0,"Before TCPRecv" & $myarray, "TCPRecv" & $myarray)
Do
        $ans = "FROM_GUI_TESTER_HELLO_11"
        $x = DLLCall( "C:\AU3Xtra.dll", "int", "TCPSend", "int", $socket, "str", $ans)

        $x = DLLCall( "C:\AU3Xtra.dll", "int", "TCPRecv", "int", $socket, "str", "", "int"
5535 )
        $myarray = "IM =::" & $x[2] & "Msg = " & $themessage

        msgBox(0,"Mess from TCL: bs = " & $x, "==" & $myarray)

; TCPSend( int<socket>, str<message> )
       $ans = "FROM_GUI_TESTER_HELLO_22"
; $x = DLLCall( "C:\AU3Xtra.dll", "int", "TCPSend", "int", $socket, "str", $ans)
; Returns # of bytes sent for success, or -1 for failure

       $ans = "FROM_GUI_TESTER_HELLO_33"
         $myarray = "Outgoing to TCL1 >>>> Message =::" & $x
         msgBox(0,"Message TO TCL: bytes = " & $x, "This Equals" & $myarray)
        $x = DLLCall( "C:\AU3Xtra.dll", "int", "TCPSend", "int", $socket, "str", $ans)

       $ans = "FROM_GUI_TESTER_HELLO_44"
         $myarray = "Outgoing to TCL2 >>>> Message =::" & $x
         msgBox(0,"Message TO TCL: bytes = " & $x, "This Equals" & $myarray)
        $x = DLLCall( "C:\AU3Xtra.dll", "int", "TCPSend", "int", $socket, "str", $ans)


        $err = @error
; If Not $err Then
;    If $x[0] >= $WSABASEERR Then ExitLoop
;    $answer = "error"
;    If $x[2] = "user" Then $answer = @UserProfileDir
;    If $x[2] = "noanswer" Then Sleep(30000); Test server not answer
;    If $x[2] = "create" Then
;       $answer = "Not created :("
;       If FileWriteLine(@Scriptdir & "\file.txt", "Created remotely") Then $answer = "File c
reated :)"
;    Endif
;    If $x[2] = "delete" Then
;       $answer = "File still here :("
;       If FileDelete(@Scriptdir & "\file.txt") Then $answer = "File deleted :)"
;    Endif
;    If $x[2] = "quit" Then
;       $answer = "Server stopped"
;       $err = 1
;    Endif
;    $x = DLLCall( "C:\AU3Xtra.dll", "int", "TCPSend",_
;                                  "int", $socket,_
;                                  "str", $answer)
; EndIf
Until $err


;CleanUp() is a wrapper for TCPShutDown
;--------------------------------------
CleanUp($socket)


;FUNCs
;++++++++++++++++++++++++++++++++++++++

Func CleanUp($CU_SOCKET)
 DLLCall( "C:\AU3Xtra.dll", "int", "TCPShutDown",_
                       "int", $CU_SOCKET)
 Exit
EndFunc

-----------------------------------------------------------------------------------------

Just trying to issue commands and getting responses back.

A Unix box controlling a PC....

TCL side - Note: replace x with the IP and y with the port

-----------------------------------------------------------------------------------

set sock_desc [socket "xxx.xxx.xxx.xxx" yyyy]
fconfigure $sock_desc -buffersize 80
fconfigure $sock_desc -blocking 0

while {1} {

    puts $sock_desc "STARTING_TCL"
    gets $sock_desc line
    puts "GUI Sent = $line"
    sleep 1

}

close $sock_desc
Edited by Larry

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.