Sign in to follow this  
Followers 0
yucatan

tcp binary data problem

18 posts in this topic

#1 ·  Posted (edited)

hello guys i have a problem i'm using tcp/ip to send large numbers of binary data

but i have this problem

sender script

If $done <> "1" then 
        ConsoleWrite("sending the beginning"&@CRLF)
        TCPSend($socket,"stream|"&$display&"|"&$read2)
        $done = "1" 
Else
    ConsoleWrite("sending data"&@CRLF)
    TCPSend($socket,"stream|"&$display&"|"&$result)
    EndIfoÝ÷ Ú·ëÞ®Ç+ZºÚ"µÍY ÌÍØ^VÌWHH   ][ÝÜÝX[I][ÝÈ[ÛÛÛÛUÜ]JÔ[É][ÝÔÝX[HÈY[ÝY][ÝÊBQ[UÜ]J    ][ÝÐÎÌLÝ[  ÌLÙ[[ÜÉÌLÉ][ÝÉ[ÉÌÍØ^VÌK    ÌÍØ^VÌ×JBQ[PÛÜÙJ    ][ÝÐÎÌLÝ[  ÌLÙ[[ÜÉÌLÉ][ÝÉ[ÉÌÍØ^VÌJB[Y

this is the server log

login|someusername|somepassword|**.**.**.**
stream|somefile.mp3|0x88000000E11D0000070000009B0215A9C79E62F330645130 and here is the rest of the binay data
73F3DE2097F847249E4D3BD more binary data
CAD1034B1208AF920F9BD6D0 more binary data
31C9195DB8F8D more binary data

can somebody explane me why there is comming binary data without any "stream|"&$display&"|"& infront of it i realy dont understand how that is posseble how my reciever script will not work because there is no "stream" before the binary data

Edited by yucatan

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

LOL, I don't understand it either, did you accidentally submit that without words in your post, or did you think your title was self-explanatory?

I'm guessing it was accidentally submitted without words. :) I'll post something relevant now.

Edited by exodius

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

hello guys i have a problem i'm using tcp/ip to send large numbers of binary data

but i have this problem

sender script

If $done <> "1" then 
        ConsoleWrite("sending the beginning"&@CRLF)
        TCPSend($socket,"stream|"&$display&"|"&$read2)
        $done = "1" 
Else
    ConsoleWrite("sending data"&@CRLF)
    TCPSend($socket,"stream|"&$display&"|"&$result)
    EndIfƒoÝŠ÷ Ú·œ‰ëÞ®Ç+Š›ZºÚ"µÍšYˆ   ˆÌÍŽØœ˜^VÌWHH   œ][ÝÜÝ™X[Iœ][ÝÈ[‚ÛÛœÛÛUÜš]JÔ“‰˜[Éœ][ÝÔÝ™X[HÈ™Y[ˆÝY‰œ][ÝÊB‚Qš[UÜš]J    œ][ÝÐΉˆÌLŽÝ[ ˆÌLŽÙ[[ÜɈÌLŽÉœ][Ýɘ[ɈÌÍŽØœ˜^VÌ—K ˆÌÍŽØœ˜^VÌ×JB‚Qš[PÛÜÙJ   œ][ÝÐΉˆÌLŽÝ[ ˆÌLŽÙ[[ÜɈÌLŽÉœ][Ýɘ[ɈÌÍŽØœ˜^VÌ—JB‘[™Y

this is the server log

login|someusername|somepassword|**.**.**.**
stream|somefile.mp3|0x88000000E11D0000070000009B0215A9C79E62F330645130 and here is the rest of the binay data
73F3DE2097F847249E4D3BD more binary data
CAD1034B1208AF920F9BD6D0 more binary data
31C9195DB8F8D more binary data

can somebody explane me why there is comming binary data without any "stream|"&$display&"|"& infront of it i realy dont understand how that is posseble how my reciever script will not work because there is no "stream" before the binary data

You might want to re-post your code using the
tags, it's not as pretty but it looks like the forum's eating your code.

Check this out and see if it gives you some guidance. Larry's kindofan all-star.

Edited by exodius

Share this post


Link to post
Share on other sites

You might want to re-post your code using the

tags, it's not as pretty but it looks like the forum's eating your code.

Check this out and see if it gives you some guidance. Larry's kindofan all-star.

i did edit my post:) thanks for the notice

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Build a binary packet manually by using the BinaryXXX functions.

It should look somewhat like this in the end:

$read2 = "" ;; $read2 is REAL binary data

$bString = StringToBinary("stream|" & $display & "|") ;; convert string into binary data

$bData = $bString & $read2

TCPSend($socket,$bData))

And on the receiving end you'll have to parse the data with BinaryToString. Easier is to modify your protocol to not do weird things like split by pipes, or use Base64 to encode your data.

I also can't stress enough how important it is to learn to use programming standards. This is a perfect example. USE A STANDARDIZED PROTOCOL LIKE HTTP.

Edited by Manadar

Share this post


Link to post
Share on other sites

Build a binary packet manually by using the BinaryXXX functions.

It should look somewhat like this in the end:

$bData = StringToBinary("stream|"&$display&"|"&$read2)

TCPSend($socket,$bData)

can u explane that a little bit bether/more i dont fully understand u manadar.

Share this post


Link to post
Share on other sites

Edited above.

The basic idea is to use AutoIt to build a real binary packet first, and then send it.. Do not assume you can concatenate binary data and strings.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Edited above.

The basic idea is to use AutoIt to build a real binary packet first, and then send it.. Do not assume you can concatenate binary data and strings.

ahh okee could u olso give a little sample on how the server should recieve this if i use your way ?

this is the server now

if $array[1] = "stream" Then
ConsoleWrite(@CRLF&"Stream has been started.")
    FileWrite("C:\temp\demos\"&$array[2], $array[3])
    FileClose("C:\temp\demos\"&$array[2])
EndIf
Edited by yucatan

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Could you post the full working code? I like to have something to play with.

here is the code of my server

Global $CurrentSocket = 0
Global $ListenSocket
Global $ConnectedSocket[16]

$TCP = TCPStartup()
If $TCP = 0 Then
    MsgBox(0, "Error", "Unable to startup TCP Services!")
    Exit
EndIf

$ListenSocket = TCPListen(@IPAddress1,1777,16)
If $ListenSocket = -1 Then
    MsgBox(0, "ERROR", "Unable to start listening on port 1777")
    Exit
EndIf
    
While 1
    $ConnectedSocket[$CurrentSocket] = TCPAccept($ListenSocket)
    If $ConnectedSocket[$CurrentSocket] <> -1 Then
        $CurrentSocket = $CurrentSocket + 1
    EndIf
    For $INDEX = 0 To 15
        If $ConnectedSocket[$INDEX] <> -1 Or $ConnectedSocket[$INDEX] <> "" Then
            $Recv = TCPRecv($ConnectedSocket[$INDEX],1024)
            If $Recv <> "" Then
            

if $array[1] = "stream" Then
ConsoleWrite(@CRLF&"Stream has been started.")
    FileWrite("C:\temp\"&$array[2], $array[3])
    FileClose("C:\temp\"&$array[2])
EndIf




            EndIf
        EndIf
    Next
    Sleep(20)
WEnd

manadar ? u requested my server co so there it is.. Help me pleas

how i can split the $var's if u dont want that i split it with pipes?

Edited by yucatan

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

manadar i have tested your script to build one binary package and that works with sending but with recieving i have only one problem

the sender

If $done <> "1" then 
        ConsoleWrite("sending the beginning"&@CRLF)
        $bString = StringToBinary("stream|" & $display & "|") ;; convert string into binary data
        $bData = $bString & $read2
        TCPSend($socket,$bData) 
        $done = "1"
Else
    ConsoleWrite("sending data"&@CRLF)
        $bString = StringToBinary("stream|" & $display & "|") ;; convert string into binary data
        $bData = $bString & $result
        TCPSend($socket,$bData)
EndIfoÝ÷ ÚØ^­ç"z÷«jëh×6               If $Recv <> "" Then
                $test = IsBinary($recv)
                if $test = 1 then $recv= BinaryToString($recv)

i use this code to detect if the $recv = binary if it is then it convert it but the binary data witch i wanted to send to the server

the only problem i have now is this look the server log

this is the server log

stream|somefile.mp3|Î
Stream has been started.
î½V11ñ¿þÓ

Æ¿C÷ÎÌ
0þ×ÿÃ


pI²

§¸5C¿ë&Ä+ã!÷À)ªG* è°.ú)

that thats not binary code so i cant write that in a file... how i can fix that ?

Edited by yucatan

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I would say something like ...

$a = StringSplit ( BinaryToString( incoming data ) )

$n = BinaryLen ( $a[1] & $a[2] + 2 ) ; This SHOULD BE the total length of the string: stream|somefile.mp3|

$bData = BinaryMid( incoming data, $n ) ; now you have the remainder of the binary data, which is the actual binary data

Edit: To avoid these kind of problems, you usually create a bit more of an elaborate protocol or use a standard protocol. Something along the lines of:

Client: I want to send you a file with name somefile.mp3

Server: Alright, send me somefile.mp3

Client: Ok, the content length is 10942

Server: I am expecting a file with length 10942 and shall store it as somefile.mp3

Client: [actual binary data]

[ optional error checking communication ]

[ connection closed ]

Edited by Manadar

Share this post


Link to post
Share on other sites

I would say something like ...

$a = StringSplit ( BinaryToString( incoming data ) )

$n = BinaryLen ( $a[1] & $a[2] + 2 ) ; This SHOULD BE the total length of the string: stream|somefile.mp3|

$bData = BinaryMid( incoming data, $n ) ; now you have the remainder of the binary data, which is the actual binary data

Edit: To avoid these kind of problems, you usually create a bit more of an elaborate protocol or use a standard protocol. Something along the lines of:

Client: I want to send you a file with name somefile.mp3

Server: Alright, send me somefile.mp3

Client: Ok, the content length is 10942

Server: I am expecting a file with length 10942 and shall store it as somefile.mp3

Client: [actual binary data]

[ optional error checking communication ]

[ connection closed ]

why i just cant send some text&"|"&somemoretext&"|"&$read2

$read2 = the binary data..

strange:S

Share this post


Link to post
Share on other sites

why i just cant send some text&"|"&somemoretext&"|"&$read2

$read2 = the binary data..

strange:S

You can... I do... It is usually referred to as the "header". But mixing strings and binary is dangerous. Always use string or always use binary. I choose to always use binary variables and keep my header info at fixed lengths or prefix variable length info with a length entry.

for instance... my data transfer may be... in cmd|datalen|data format cmd being 8 characters, datalen being 4 bytes (int to bin (send / recv) bin to int.), and data

looking something like this when transferred...

msgbox..|$h^s|I am a message

You really have to be robust about your header structure and your binary data handling. Force variables to Binary() when applicable... before "concatenation".

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

You can... I do... It is usually referred to as the "header". But mixing strings and binary is dangerous. Always use string or always use binary. I choose to always use binary variables and keep my header info at fixed lengths or prefix variable length info with a length entry.

for instance... my data transfer may be... in cmd|datalen|data format cmd being 8 characters, datalen being 4 bytes (int to bin (send / recv) bin to int.), and data

looking something like this when transferred...

msgbox..|$h^s|I am a message

You really have to be robust about your header structure and your binary data handling. Force variables to Binary() when applicable... before "concatenation".

Lar.

yeah i understand that lar thx for ur usefull post but i still didnt find a way to get this working but i'm working on it if u have anymore good advice of sample's then u pleas post

Yucatan.

Share this post


Link to post
Share on other sites

It is advanced. You don't want to block execution... you need to set up arrays of socket info, if you are allowing more than one connection. You need to TCPRecv until you have the full header to parse. You need to Check the return of TCPSend to make sure all of the data was sent. You need to keep adding the TCPRecv to a buffer (a $variable) until it satisfies your length requirements.

Nothing in TCP should be coded without much attention to detail. Make no assumptions. I have written so many of these that I am rather sick of them. I have some examples on the forum. search my name and tcp ... like +larry +tcp +server ...

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

yeah i understand that lar thx for ur usefull post but i still didnt find a way to get this working but i'm working on it if u have anymore good advice of sample's then u pleas post

Yucatan.

hey guys it is not working with ur idea larry but the problem still exsist here is the recievers code

If $ConnectedSocket[$INDEX] <> -1 Or $ConnectedSocket[$INDEX] <> "" Then
            $Recv = TCPRecv($ConnectedSocket[$INDEX],999999999)
                If $Recv <> "" Then
                    $binary = IsBinary($Recv) 
                    if $binary = "1" then 
                    $recv2 = BinaryToString($Recv)
                    ConsoleWrite(@CRLF&BinaryLen($recv)&" " &$recv2)
                    $array = StringSplit($Recv2, "|")
        Else
                    $array = StringSplit($Recv, "|")        
EndIfoÝ÷ Ú«zçÇ"¸­zØ^­ç"z÷u«ZvWºÚ"µÍY ÌÍØ^VÌWHH   ][ÝÜÝX[I][ÝÈ[ÌÍØØÚHH[SZY
    ÌÍÜXÝ   ÌÍØ^VÌ×JBÌÍÜÙYH[S[ ÌÍÜXÝBÛÛÛÛUÜ]JÔ[É][ÝÔÝX[HÈY[ÝY][ÝÉ[ÉÌÍÜÙY
BQ[UÜ]J    ][ÝÐÎÌLÝ[  ÌLÙ[[ÜÉÌLÉ][ÝÉ[ÉÌÍØ^VÌK    ÌÍØØÚJBQ[PÛÜÙJ  ][ÝÐÎÌLÝ[  ÌLÙ[[ÜÉÌLÉ][ÝÉ[ÉÌÍØ^VÌJB[Y

and here is the reciever log from console

8760 stream|demo0028.dm_1|21|\
Stream has been started.8760
14600 ½wÇkÐV±pø[¶Ê)°ÈyBU]¿£Æü³Ö ­»Û@ãã\þãGj j»4Eòú`
64240 <~øO
64240 ã²éU¶{G^Åë»ÉK¯øõÄ£±ÜÌQ¦l1^HèþÕgd9æ¥Wy_ìTäèÁ)ú+Li(UzdÊóÒ«tÜñÓ|öÇC<ýVèR£9$«Í
64240 D×¥W¡£8!({Øî0¯K¯">ôð¤W¡\iýuLV£ë4kóýN
64240 U¶{÷d\¬âuµ;ÆÅ*ÍÅx|q©ð¯áÐï:öÆÅ*a°x¾ß~üU.
t9ôþèia<á=¤7
Ùt¤¸ù¬~Þ  
64240 
64240 
64240 `ß´åëh¹v8Yõc¬<ÀÀå5Y}Ñþ`;¬Õ
64240 ±Ü¯«0
64240 O¦cWêÕQgê­
64240 
64240 ¬²Ý2ÔsVñº*ÔsV).·\ºÅx'Å
P­¡¡â.õUÆéXqsCDrTÆ:u-¹;ÝË ³Ôê9«k¦±ü¨K!!Å'¾ñ%fõá
64240 g
64240 ö!h<¬V龪mÙ[
K'$75Õ8Ò{ÿÒMhð°ZU`kÎ<º&º¸TnÙÅ@ÀÃj\±jnÍÜG²è 
64240 l÷^¡°´×MVÉwxX¡æ»
íöº4WXZ%bÍ"ˬYïásÌ x¥°´
;ì\ai îi&×ù~t#
64240 
64240 ¯(
64240 }»È!ø«Pÿk+
64240 .³Ð:ºþ*8<trþ¥û_eã-3ÖùìÉ-
64240 æ³3÷s!÷C0
64240 ª×Mú"ßþUrÿÊì2çMç"¾ú!3
64240 å÷Ûõh~¬~.6
64240 ÊÝ;ú\º[rÝ|.Ý­BüúÀ×Ù(ú±@ÿI.Ý­ÂúÄ×Ä9¸¾ê#Ù?X9
64240 ¯²C÷æ®Èu´×Ï¿Ê@Þ   @½<88":Ê29¸þ
Óc\?ÿ*§¹þµ$Àå"=
64240 ßÄ@
64240 
éD
64240 yºw`¼
ä:ÅÆG^õÜ0®Â@À3õ|ÙøÈ«öx|F÷Ü?ÍH
64240 
64240 
64240 oq]F-EýhR
64240 _fRA¢ëèÒ*«P¾rF>¾E÷FÿÎU
64240 c¦ýÚAÆ^e¾Y
64240 r9±W°Çxc¦~
:±WY³ ññWýp|ÃLòï
\
64240 ÖFVe
OjÍÜNÿûÿ×À»Þ*c¯×|´U»Þ*¼?vc?¬=8ÅÞ>Pd5ÍÊß!Ivþï^
64240 ©Ê
64240 
64240 ø\RÅ0ÓÃZEzU¿±)ïõÑhÔ

­2×UôÁ¤æ¥ðÃ
ô½R¬~dg
64240 OVÙ¡{÷g|²Jh!­<ãUú¹¡ëq¤Sy¤Ô·G<ãU¢Ñæf|²Êã5±7î>oáCÕrø£DWpÆ'«dt|Áâøo¸eÕj
64240 ÚóOMkúGl
64240 
@§"gC¼û­¢ùÔ«Ìezñ`<#ÿ¢Ë$û¸n
64240 üÄÖUÍcµ×¢m7zý3q
64240 ¸"Ùoiâ÷*0\Æàæ.Á}HFOcõ®t
64240 ì4«,ÅÌèx"F¯ëbÅù~¾x
64240 )øAüeHé¹`¦Y¥ñ;,"~9úþÌy
¾WoHê|
64240 
Ê%È*ul>ñ:ø^LV?m
64240 
64240 
(n) Ñ=
ùÓ{,U(»   è]%Z3vÔ[ù¸oÅÓW|hiâÑ5»ÊÁ¸¡E¬O)pêð\½!Ë?7
64240 ½(~©ÆZ3ƣͤöÛdůÒÉG.wÐl×qåSÔhÔ×A;Pü*¬wÌ`vdÿ
64240 <PeJ) Ã%j"¤?þ
64240 KY3ÄS¬¹3iS]G˯`þ«ßTàc.®ÏÆx¥
(ÿú
64240 Ë#?Ú[wôì!®ñÞÆÞ(ðó£I¿Ñ¶$²øù~Ë
64240 ع£^%Ò
64240 £Eó«ìн,_%ôº4½Eó«ÑT>sy#Îlqx,æ´)ê2æ¦ÊÙ½§_^Çø54mhÑü*P¹úK
64240 wz
0~ð¤?J
64240 @ºù ¥UV¾|¤ýÿµ
64240 
64240 
64240 ÕoÂ;e3±¶J¦å?¿H½b,°¶JÁ8°s[ÇÄ-®#
©ùùQ$ÉË?Ù£
64240 þV¸~
ö/O¾üTÌGÃËÿ«tnn½Í=Ä$V.*e¦ÊðÏ°ÊånÆDSXÆD¯þRã;c_EþVYùzTá+}~äþ¦
64240 ÐÀT>èsàkcÀúþÅ
64240 ½bÖ(ö¸âuè¥o9ÜëV¡ê8b÷=¨~ä*
¥Ædõ²ª
64240 RTiÊG¡`ñãhs
þø§åæF¾éEÁ*ÅÀ®`ßãrÆȵ
ç;VäG+,½(Xe½5{Gó!³·~^·"éò¬
64240 sé7®iÒvmKîôùAd F~wXåÙ®
64240 Ðo¤ÔézQgÕ{Ñü=³üqóÓEÙ(«Ë°
64240 dèÞÃEƹ×-X+2ÎUê6pc$^>$Â_±¼I0·tÏ"ã\%·Ló+·þ;:¤xV8"¢EÐ+2ÎU??-"î"ã\økÑ/À$Ù?
³
64240 ¡
64240 
64240 á0Äé¯rêægãP9ÙÉ1© 
64240 À[e»÷1
ðV -¬ùS·Ê¯aí£ênÏ£
64240 ¹"ÆÁºüÂ
64240 
64240 op˹~¬~ÈÈ
64240 ~q×Ô$ßPÕ\kªÊ?tÌ
64240 öò*Û½qæ]^åõÿ~Õ
64240 ÔÞ
64240 ½°«¼þ&è
64240 ×ÿoñ
64240 Êvïñ(̼Êëÿºú
64240 #­òúï
64240 
58568 ÎDWÙî}Ý4Ï«¼þk
4119 stream|somefile.mp3|21
Stream has been started.4119
4119 stream|somefile.mp3|21
Stream has been started.4119

u see larry i'm still recieving data that does not start with stream|

so i cant write the data away

any idea's?

Edited by yucatan

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  
Followers 0