How to send large numbers via UDP?

4 vues (au cours des 30 derniers jours)
Adam Gozdowski
Adam Gozdowski le 15 Sep 2019
Hello.
I would like to know if I can recieve integers larger than 127 (fscanf) or 255 (fread). I am sending them via UDP datagram from C++ based application and how to do it. I can send them as char, but they are coded as utf16 in visual studio, and utf8 in matlab, so there is overload after 127 as well.
Thank you.
Adam

Réponses (1)

Walter Roberson
Walter Roberson le 15 Sep 2019
What is coding them as utf16 ?
In any case, use native2unicode() to convert raw bytes that are UTF8 or UTF16 into MATLAB characters . You will need to know whether it is UTF16-LE or UTF16-BE
But normally you would just fwrite() them from the source and fread() them on the destination and have the destination adjust the byte order according to the documentation (hint hint) that the source provides about what the byte order is.
Possibly in the context of UDP, you might want to typecast() everything you want to send to uint8() and append it all into one vector, and then fwrite() the vector. Though I suppose in C++ you would use a reinterpret cast.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by