ripdad Posted June 13, 2014 Share Posted June 13, 2014 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 More sharing options...
jpm Posted June 13, 2014 Share Posted June 13, 2014 @ripad post #19 I don't understand where the -2 must be returned with your script. How can I reproduce it Thanks again for your testing Jpm Link to comment Share on other sites More sharing options...
bogQ Posted June 13, 2014 Share Posted June 13, 2014 (edited) 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 June 13, 2014 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) 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 More sharing options...
ripdad Posted June 13, 2014 Share Posted June 13, 2014 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 More sharing options...
ripdad Posted June 13, 2014 Share Posted June 13, 2014 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 More sharing options...
bogQ Posted June 13, 2014 Share Posted June 13, 2014 (edited) yea i did not understand that it keeps on hanging (newer exit client) ;Ptought that your client just exits with no msgbox so thats why i assumed it exit client coz of some previous errorswell at least i know that error 10054 is displayed correctly on client when dccing server with no TCPCloseSocket Edited June 13, 2014 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) 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 More sharing options...
ripdad Posted June 13, 2014 Share Posted June 13, 2014 (edited) 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 June 13, 2014 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 More sharing options...
JScript Posted June 20, 2014 Author Share Posted June 20, 2014 (edited) 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) = $iBmpSizeI 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 = $iBmpSizeEdit1:According to http://msdn.microsoft.com/en-us/library/windows/desktop/ms740121(v=vs.85).aspxIf 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 = $iBmpSizeBefore 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 June 20, 2014 by JScript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
jpm Posted June 20, 2014 Share Posted June 20, 2014 Slight error If $aRecv[0] Then must be If $aRecv[0] > 0Â Then Link to comment Share on other sites More sharing options...
JScript Posted June 20, 2014 Author Share Posted June 20, 2014 (edited) @jpmYes, 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 June 20, 2014 by JScript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
bogQ Posted June 20, 2014 Share Posted June 20, 2014 (edited) 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 June 20, 2014 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) 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 More sharing options...
JScript Posted June 20, 2014 Author Share Posted June 20, 2014 (edited) @bogQIn 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=1And 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 June 20, 2014 by JScript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
bogQ Posted June 20, 2014 Share Posted June 20, 2014 (edited) 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 June 20, 2014 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) 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 More sharing options...
JScript Posted June 20, 2014 Author Share Posted June 20, 2014 @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 Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
bogQ Posted June 20, 2014 Share Posted June 20, 2014 (edited) 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 errori 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 June 20, 2014 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) 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 More sharing options...
JScript Posted June 20, 2014 Author Share Posted June 20, 2014 @bogQ I've tried with "While loop", but it was much slower than using "Do Until"Anyway I'll wait for your results! JS http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
bogQ Posted June 20, 2014 Share Posted June 20, 2014 (edited) 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 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 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)vsWhile 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 maybeedit quick fixWhile 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 June 20, 2014 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) 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 More sharing options...
JScript Posted June 20, 2014 Author Share Posted June 20, 2014 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 Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
ripdad Posted June 22, 2014 Share Posted June 22, 2014 (edited) My stab in the dark for now. Still needs a recv timeout on blocking socket. - edit- code deleted to avoid confusion. Edited June 29, 2014 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 More sharing options...
ripdad Posted June 24, 2014 Share Posted June 24, 2014 (edited) 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 June 29, 2014 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now