How to send large numbers via UDP?
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Walter Roberson
2019-9-15
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 JSON Format 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!