How to send byte aligned structures via UDP sockets?

3 views (last 30 days)
Hello,
I was curious as to how you send byte aligned structures via MATLAB'S UDP sockets. I am using MATLAB to interface with a C program that expects the following structure
typedef struct{
int member_1;
int member_2;
int member_3;
int member_4;
float member_5;
float member_6;
float member_7;
float member_8[256];
} T_Mystruct;
The size of this structure in bytes is 1052 bytes which is under the windows MTU size for UDP packets. The issue is that this data needs to be all in one packet. If I construct the packet like this in matlab,( which i tired)
msg_1 = [ member_1,member_2,member_3,member_4];
msg_2 = [ member_5,member_6,member_7];
msg_3 = member_8;
fwrite(udp_socket,msg_1, 'int32')
fwrite(udp_socket,msg_2, 'float32')
fwrite(udp_socket,msg_3, 'float32')
this sends the right number of bytes but the wrong number of packets. Is there any way to condense this into one packet, that is byte aligned to the above format? I considered this:
packet = [msg_1,msg_2,msg_3];
fwrite(udp_socket,packet,'????');
but then what do you put for the precision ? it would be nice to just tell it how many bytes to write as a "custom" precision . thank you for your time.

Answers (0)

Categories

Find more on Interface-Based Instrument Communication in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!