Page 1 of 1

Use non ASCII transmission with UDP

Posted: Thu Jul 02, 2009 3:38 pm
by tal
Hi,

I have a big problem, i want to make an UDP connection beetween Revolution and another application, but the other application sends data in binary form and Revolution recepts this data as ASCII...
How can i do to change this?

Thanks

Posted: Thu Jul 02, 2009 4:52 pm
by Mark
Hi tal,

This is not true. Data enters the socket in unaltered form. "Binary" just means that thedata cannot be interpreted as text. Examples are pictures and unicode.

If the "other" programme delivers picture data, you need to figure out the format of the picture. If the "other" programme delivers unicode data, you need to find out whether this is UTF8, UTF16 or something else. If the "other" programme delivers data in a special format, you need to check the documentation of that programme and find out how to parse the data.

Do you have any additional information about that "other" application?

Best regards,

Mark

Posted: Thu Jul 02, 2009 9:14 pm
by Janschenkel
The read from socket command can also read individual bytes or a group of bytes and interpret them as uInt4 (32-byte unsigned integer) and other formats.
Also take a look at the binaryDecode and binaryEncode functions that can help you convert from and to binary formats.

HTH,

Jan Schenkel.

Posted: Fri Jul 03, 2009 9:38 am
by tal
ok thanks for your replies,

-we must use the UDP protocol in our connection and it seems that the syntax ih the UDP protocol in rev does not allow the "read form socket" instruction , here is an example :

on mouseUp
accept datagram connections on port 10000 with message gotPacketFrAppOne
end mouseUp

on gotPacketFrAppOne pHost, pMsg, pSocket
answer "Received from "& pHost
answer "on socket " & pSocket
answer "with the following text "&cr & pMsg
end gotPacketFrAppOne

-the data is stored in pMsg without doing a "read from file" and when it is interpreted automatically as ASCII code instead binary code.

-If you know an instruction that can avoid the ASCII interpretation of the data transmitted, it would be very helpfull.

-the data recieved is corrupted because of the ASCII interpretation and we can not recover the data and use its value ( binarydeocde or encode....)

PS : the data recieved are integers (or singles) encoded in binary.

Posted: Fri Jul 03, 2009 10:03 am
by SparkOut
What is the data that you are expecting?
In your example, you seem to be expecting text...

Code: Select all

answer "with the following text "&cr & pMsg
where the "answer" dialogue will only be able to try and interpret the content as text to display the output anyway. You could never (for example) "answer" a jpeg image. Binary data is binary data and it will look like whatever the "viewing tool" interprets it as. If you are using a text handler to display the binary data, then it will appear as ascii output. The character "A" that you see on the screen in that "character" position will still be a data value byte containing 65. If you want to check the data received and display it, so that you see "65" shown on screen, then you would need a function to convert the data value "65" to a string of two characters "6" (ascii 54) and "5" (ascii 53) in order to render that on screen.
If you interpret it with another handler that is manipulating the data in the expected way as binary, then can you give an example of the errors you are getting? Simply "answering" the data received will not mean that it is converted though - you will never be able to "see" raw binary bits.
If you (for example) take the received data and

Code: Select all

put pMsg into url ("binfile:" & myDataFile)
then does that file contain the data you want? (bearing in mind that if you opened that data file in a text editor, then you will get similar "ascii" output displayed as with the answer handler in Rev).

Posted: Mon Jul 06, 2009 2:36 pm
by tal
Thanks, we tried this script to read with revolution a data send in a binary form and it works.


on mouseUp
enable btn "con"
accept datagram connections on port 60001 with message gotPacketFrAppOne
end mouseUp

on gotPacketFrAppOne pHost, pMsg, pSocket


put 12 into compteur

--number of values

put (chartonum(char 1 of pMsg) * 2^24 + chartonum(char 2 of pMsg )* 2^16 + chartonum(char 3 of pMsg) * 2^8 + chartonum(char 4 of pMsg)) into n

put (n-12)/4 & "valeurs" into field "info"

--show the value
repeat until compteur >= n

put (chartonum(char 1+compteur of pMsg) * 2^24 + chartonum(char 2+compteur of pMsg )* 2^16 + chartonum(char 3+compteur of pMsg) * 2^8 + chartonum(char 4+compteur of pMsg)) & " " after fld "result"

put compteur+4 into compteur

end repeat

end gotPacketFrAppOne


I have another question, we can send a frame in a binary form but Revolution always add at the end of the frame " 0A" (Line Feed).
How can we delete "0A" in the udp transaction?

Best regards.

Posted: Mon Jul 06, 2009 2:56 pm
by Mark
Tal,

delete last char of pMsg

or

put char 1 to -2 of pMsg into pMsg

Best,

Mark