Jump to content

TCPRecv and v3.3.12.0


Recommended Posts

It's just a quick script with a local connection.

It's only for testing and should serve its purpose.

It can also be modified easily, if needed.

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

on client infinite loop it dont exit from it on error

hes expecting -2 error when server disconnect socket to recive it on tcprecv error on "do untill" loop

lines 30 to 33

 

Client just keep on hanging

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

jpm,

Well, I tried to make a visual script. I see now that it probably was a bad idea.

It doesn't matter anyway -- the modified .exe is not detecting a server disconnect

as earlier versions did. Just wanted to make you aware of it.

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

bogQ,

I coded it that way on purpose. I'm sorry you don't understand.

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

yea i did not understand that it keeps on hanging (newer exit client) ;P

tought that your client just exits with no msgbox so thats why i assumed it exit client coz of some previous errors

well at least i know that error 10054 is displayed correctly on client when dccing server with no TCPCloseSocket :)

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Good morning everybody -- first cup of coffee, hmmm.

jpm,

It doesn't "return -2", because it never received an @error.

It's still waiting for it in the loop.

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

I'll give a hint about the function that I believe it is easy to implement:

Return the number of bytes received in the @extended macro, because that way we would have more speed in loops!

See the code below:

Do
    $sScrn = TCPRecv($iConnected, $iChunk, 1)
    If @error > 0 Then
        Return 0
    EndIf
    If $sScrn Then
        $bBmp &= BinaryToString($sScrn)
    EndIf
Until StringLen($bBmp) = $iBmpSize

I think it would be much faster if it were written like this:

Do
    $sScrn = TCPRecv($iConnected, $iChunk, 1)
    If @error > 0 Then
        Return 0
    EndIf
    If $sScrn Then
        $bBmp &= BinaryToString($sScrn)
    EndIf
Until @extended = $iBmpSize

Edit1:

According to http://msdn.microsoft.com/en-us/library/windows/desktop/ms740121(v=vs.85).aspx

If no error occurs, recv returns the number of bytes received and the buffer pointed to by the buf parameter will contain this data received. If the connection has been gracefully closed, the return value is zero.

Someone could translate this to AutoIt?

int recv(
  _In_   SOCKET s,
  _Out_  char *buf,
  _In_   int len,
  _In_   int flags
);

Edit2:

I got this result and it worked:

Local $tBuffer = DllStructCreate("char buf[1024]")
    Local $aBytes = DllCall("Ws2_32.dll", "int", "recv", "int", $iSocket, "ptr", DllStructGetPtr($tBuffer), "int", DllStructGetSize($tBuffer), "int", 0x02) ;<-MSG_PEEK
    $aBytes = $aBytes[0]

Edit3:

I did several tests with the code below and the results were amazing!

Local $tTcpBuffer = DllStructCreate("byte[" & $iBmpSize & "]")
Local $pTcpBuffer = DllStructGetPtr($tTcpBuffer), $aResult = 0, $iBytes = 0
Local $iBufLen = $iBmpSize

Do
    $aResult = DllCall($hWs2_32, "int", "recv", _
            "int", $iConnected, _
            "ptr", $pTcpBuffer, _
            "int", $iBufLen, _
            "int", 0) ;<-MSG_WAITALL

    If $aResult[0] Then
        $iBytes += $aResult[0]
        $iBufLen -= $aResult[0]
        $bBmp &= BinaryToString(DllStructGetData($tTcpBuffer, 1))
    ElseIf $aResult[0] = 0 Then
        ContinueLoop
    Else
        _CloseRecStream($iConnected, $hGuiRec, $bKbdProc)
        MsgBox(262160, "BMP data error -> " & @error, "A conexão com o computador remoto falhou!")
        Return 0
    EndIf
Until $iBytes = $iBmpSize

Before I just could quickly send JPG images, but now even PNG images are being received with greater speed!

Edit4:

Much better with Adjust the buffer position and size:

$tTcpBuffer = DllStructCreate("byte[" & $iBmpSize + 256 & "]") ; Ensures that the temporary "alignement" buffer is large enough
                $pTcpBuffer = DllStructGetPtr($tTcpBuffer)
                $iBufLen = $iBmpSize
                Do ;---------------------------------| Exactly the amount of $iBmpSize bytes to read
                    $aRecv = DllCall($hWs2_32, "int", "recv", "int", $iConnected, "ptr", $pTcpBuffer, "int", $iBufLen, "int", 0)

                    If $aRecv[0] Then
                        ; Adjust the buffer position and size
                        $pTcpBuffer += $aRecv[0]
                        $iBufLen -= $aRecv[0]
                    ElseIf $aRecv[0] = 0 Then
                        ContinueLoop
                    Else
                        _CloseRecStream($iConnected, $hGuiRec, $bKbdProc)
                        MsgBox(262160, "BMP data error -> " & @error, "A conexão com o computador remoto falhou!")
                        Return 0
                    EndIf
                Until $iBufLen = 0

                $bBmp = DllStructGetData($tTcpBuffer, 1)

JS

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

@jpm

Yes, I thought it was wrong but look at the result: '>

I let the program run for 40 minutes and did not give any problem!

The results are amazing!

With TCPRecv only reached 7 FPS, now gets between 11 and 17 FPS. It is a very good gain speed.

JS

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

See the code below:

if i understand correctly your mixing msgs (sending pictures) and your splitting them up with lenght comparison but your comparing length of data on every loop till length is correct?

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

@bogQ

In fact this was the quickest way I found to transmit remote frame:

Server:

TCPSend ($ IConnection, BinaryToString ($ bBitmap))

Client:

Do ;---------------------------------| Exactly the amount of $iBmpSize bytes to read
    $sScrn = TCPRecv($iConnected, $iChunk, 1)

    If @error > 0 Then
        _CloseRecStream($iConnected, $hGuiRec, $bKbdProc)
        MsgBox(262160, "BMP data error -> " & @error, "A conexão com o computador remoto falhou!")
        Return 0
    EndIf
    If $sScrn Then
        $bBmp &= BinaryToString($sScrn)
    EndIf
Until StringLen($bBmp) = $iBmpSize
$bBmp = StringToBinary($bBmp)

It is the same format used for the other program: http://www.autoit.de/index.php?page=Thread&threadID=24989&pageNo=1

And I did several tests with other formats, but unfortunately this was the fastest!


But now I'm using this way:

Server:

DllCall($hWs2_32, "int", "send", "int", $iConnection, "ptr", $pMemStream, "int", $iBmpSize, "int", 0)

Client:

Do ;---------------------------------| Exactly the amount of $iBmpSize bytes to read
    $aRecv = DllCall($hWs2_32, "int", "recv", "int", $iConnected, "ptr", $pTcpBuffer, "int", $iBufLen, "int", 0)

    If $aRecv[0] Then
        ; Adjust the buffer position and size
        $pTcpBuffer += $aRecv[0]
        $iBufLen -= $aRecv[0]
    ElseIf $aRecv[0] = 0 Then
        ContinueLoop
    Else
        _CloseRecStream($iConnected, $hGuiRec, $bKbdProc)
        MsgBox(262160, "BMP data error -> " & @error, "A conexão com o computador remoto falhou!")
        Return 0
    EndIf
Until $iBufLen = 0

$bBmp = DllStructGetData($tTcpBuffer, 1)
JS Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

is your client informing server that he can send another file (another picture)? or server is just sending and client is receiving with no confirmation that transfer is done per picture?

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

@bogQ

Yes, in this way:

; Send request to new bitmap
_SendData($iConnected, "#SndStream", DllStructGetData($tMKEvents, 1), DllStructGetData($tBitmap1, 1))

; Clears the current values
DllStructSetData($tMKEvents, 1, $bVoidEvents)
DllStructSetData($tBitmap1, 1, $bVoidBitmap1)

JS

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

if that is the case then it's safe to assume that you don't need to check size of data received till received data is equal to null and func don`t return any error

i would try to with StringLen() with 'while' loop instead 'do until', and compare will that speed up your loop little more maybe.

Any info of how many 'do untill' loops per picture does your client need to receive one frame?

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

i did not tell you that "i will try", i told you that "i whud would" :)

but i don't mind trying today or tomorrow just for fun of it :P

my english was always in a mess, so sometimes it's hard to share opinion so that other side can understand correctly what i meant to say :P

newer the less im still interested on how many 'do untill' loops per picture does your client need to receive one frame?

edit: something like this

 

While 1
    $aRecv = DllCall($hWs2_32, "int", "recv", "int", $iConnected, "ptr", $pTcpBuffer, "int", $iBufLen, "int", 0)
    Select
        Case $aRecv[0]
            ; Adjust the buffer position and size
            $pTcpBuffer += $aRecv[0]
            $iBufLen -= $aRecv[0]
        Case Not $aRecv[0]
            If $iBufLen = 0 Then ExitLoop 1
            ContinueLoop
        Case Else
            _CloseRecStream($iConnected, $hGuiRec, $bKbdProc)
            MsgBox(262160, "BMP data error -> " & @error, "A conexao com o computador remoto falhou!")
            Return 0
    EndSelect
WEnd

$bBmp = DllStructGetData($tTcpBuffer, 1)
vs

While 1
    $sScrn = TCPRecv($iConnected, $iChunk, 1)
    If $sScrn Then
        $bBmp &= $sScrn
    Else
        If @error > 0 Then
            _CloseRecStream($iConnected, $hGuiRec, $bKbdProc)
            MsgBox(262160, "BMP data error -> " & @error, "A conexao com o computador remoto falhou!")
            Return 0
        EndIf
        If StringLen(BinaryToString($bBmp)) = $iBmpSize Then ExitLoop 1
    EndIf
WEnd
;~ $bBmp = StringToBinary($bBmp)
or maybe

edit quick fix

While 1
    $bBmp &= TCPRecv($iConnected, $iChunk, 1)
    Select
        Case Not @error
            ContinueLoop
        Case @error = -1 ;or "Case @Extended = -1" with jpm test version
            If StringLen(BinaryToString($bBmp)) = $iBmpSize Then ExitLoop 1
        Case Else
            If @error > 0 Then
                _CloseRecStream($iConnected, $hGuiRec, $bKbdProc)
                MsgBox(262160, "BMP data error -> " & @error, "A conexao com o computador remoto falhou!")
                Return 0
            EndIf
    EndSelect
WEnd
;~ $bBmp = StringToBinary($bBmp)
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

After several tests I realized that now is the delay in transmission of image, so much so that only this line:

DllCall ($ hWs2_32, "int", "recv", "int", $ iConnected, "ptr", $ pTcpBuffer, "int", $ iBufLen, "int", 0)
Out of the loop is enough to receive the data, because the socket is in block mode 

The problem now is to make the server send the image with socket in non-blocking mode!

JS

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

My stab in the dark for now. Still needs a recv timeout on blocking socket.

- edit- code deleted to avoid confusion.

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

Okay, here's another stab and is up for review.

I made it as an include this time, so you can test it in your scripts without

doing too many modifications and to test the error returns.

Just #include this script and replace TCPRecv with _WSA_TCPRecv and you're good

to go.

I downloaded a 1.2GB file with it today and it was also tested for server

disconnects with no problems.

Please review the code to find out what to expect from this script.

jpm,

I think I figured out what the problem is with disconnect -2.

There's a mention of it in the script below.

There are 3 possible returns from "recv".

1. blank = no bytes received.

2. 0 = disconnected.

3. greater than 0 = bytes received.

Thanks goes to ProgAndy and JScript -- I borrowed some of their code.

The non-blocking code by ProgAndy, was obtained from here:

?do=embed' frameborder='0' data-embedContent>

- edit- code deleted to avoid confusion.

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...