Jump to content

tcprecv and binary data


kned
 Share

Recommended Posts

im using this in my download script:

$sDataBuff = TCPRecv( $hSocket, 1024)

when i try to get a picture from a http server this way i always get binary data

BinaryToString($data) works but just gives me pieces of data

my packet capture tool shows me that i got the data but autoit doesnt get it or only gets pieces

already searched the forum but didnt find anything

any ideas?

Link to comment
Share on other sites

  • Moderators

im using this in my download script:

$sDataBuff = TCPRecv( $hSocket, 1024)

when i try to get a picture from a http server this way i always get binary data

BinaryToString($data) works but just gives me pieces of data

my packet capture tool shows me that i got the data but autoit doesnt get it or only gets pieces

already searched the forum but didnt find anything

any ideas?

I love that saying.. "I searched the forum but didn't find anything", if you searched, you found plenty, now whether you felt like wading through all of the data is a different story.

How big is the string your sending in binary?

I'd suggest you show the client/server script you're using.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

im not sending anything

$req="GET images.jpg HTTP/1.1"&@CRLF
    $req&="Host: somehost.info"&@CRLF
    $req&="Range: bytes=0-"&@CRLF
    $req&="User-Agent: some client"&@CRLF
    $req&="Accept: */*"&@CRLF
    $req&="Referer: "&$link&@CRLF
    $req&="Accept-Encoding: "&@CRLF&@CRLF

gets send to a http server, so i get the picture back

in my case its a 700kb picture, but autoit only gets parts of the data after binarytostring($picturedata)

Link to comment
Share on other sites

  • Moderators

im not sending anything

$req="GET images.jpg HTTP/1.1"&@CRLF
    $req&="Host: somehost.info"&@CRLF
    $req&="Range: bytes=0-"&@CRLF
    $req&="User-Agent: some client"&@CRLF
    $req&="Accept: */*"&@CRLF
    $req&="Referer: "&$link&@CRLF
    $req&="Accept-Encoding: "&@CRLF&@CRLF

gets send to a http server, so i get the picture back

in my case its a 700kb picture, but autoit only gets parts of the data after binarytostring($picturedata)

I imagine that autoit is only getting 1024 characters, they way you have it set up.

Do you have your TCPRecv in a loop?

Did you try increasing the size limitation?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

i am using async sockets posted somwhere in the forum

_ASockSelect( $hSockets[ $i ], $hNotifyGUI, $WM_USER + $i, BitOR( $FD_READ, $FD_WRITE, $FD_CONNECT, $FD_CLOSE ) )

GUIRegisterMsg( $WM_USER + $i, "OnSocketEvent" ) ; onevent run func ..

_ASockConnect( $hSockets[ $i ], $IP, $PORT )

Func OnSocketEvent( $hWnd, $iMsgID, $WParam, $LParam )

Case $FD_READ; Data has arrived!

$sDataBuff = TCPRecv( $hSocket, $N_MAXRECV)

_FileWriteAPI($fhandles[$shandle[$id]], binarytostring($sDataBuff), $filepointer[$id])

endfunc

these are the main parts of the script

on change call onsockevent

if event=read then receive

and write to file ...

the original picture is filled with signs, the data which gets written to the file is like " *empty lines* *about 100 signs* *more empty lines*"

Link to comment
Share on other sites

  • Moderators

i am using async sockets posted somwhere in the forum

_ASockSelect( $hSockets[ $i ], $hNotifyGUI, $WM_USER + $i, BitOR( $FD_READ, $FD_WRITE, $FD_CONNECT, $FD_CLOSE ) )

GUIRegisterMsg( $WM_USER + $i, "OnSocketEvent" ) ; onevent run func ..

_ASockConnect( $hSockets[ $i ], $IP, $PORT )

Func OnSocketEvent( $hWnd, $iMsgID, $WParam, $LParam )

Case $FD_READ; Data has arrived!

$sDataBuff = TCPRecv( $hSocket, $N_MAXRECV)

_FileWriteAPI($fhandles[$shandle[$id]], binarytostring($sDataBuff), $filepointer[$id])

endfunc

these are the main parts of the script

on change call onsockevent

if event=read then receive

and write to file ...

the original picture is filled with signs, the data which gets written to the file is like " *empty lines* *about 100 signs* *more empty lines*"

That information isn't very helpful, and I'm certainly not going to chase something down to help when you've should have posted everything to begin with (including the functions you're referring too, not just their calls).

You also may want to use code tags when you post code:

**code here**[ /code] (without the space after the bracket)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Not sure what you're trying to achieve with that BinaryToString().

When converting to string, binary gets cut off at first null byte (terminator char in strings). Binary data can have a lot of null bytes. Image is binary data. So if you want to write to file, don't convert to string and use binary write mode.

"be smart, drink your wine"

Link to comment
Share on other sites

  • Moderators

Not sure what you're trying to achieve with that BinaryToString().

When converting to string, binary gets cut off at first null byte (terminator char in strings). Binary data can have a lot of null bytes. Image is binary data. So if you want to write to file, don't convert to string and use binary write mode.

Good point, I typically Base64 mine.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...