Use non ASCII transmission with UDP

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
tal
Posts: 84
Joined: Thu Jul 02, 2009 3:27 pm

Use non ASCII transmission with UDP

Post by tal » Thu Jul 02, 2009 3:38 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Jul 02, 2009 4:52 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Thu Jul 02, 2009 9:14 pm

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.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

tal
Posts: 84
Joined: Thu Jul 02, 2009 3:27 pm

Post by tal » Fri Jul 03, 2009 9:38 am

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.

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Fri Jul 03, 2009 10:03 am

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

tal
Posts: 84
Joined: Thu Jul 02, 2009 3:27 pm

Post by tal » Mon Jul 06, 2009 2:36 pm

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.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Jul 06, 2009 2:56 pm

Tal,

delete last char of pMsg

or

put char 1 to -2 of pMsg into pMsg

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply