I was wondering if anyone could help me, I’m trying to send various packets of data over network via UDP. I’m using the sendto() function in winsock2.
I’m trying to send different data types over UDP, for example; I have positional data such as:
int time; float LAT; double LONG; unsigned int ALT
I have two problems:
How to package the data ready to send: as I understand it I have to reverse the byte order?
How to send the data using the sendto() that takes a const char pointer
This is what I’ve got so far:
// create a message to put all the data types into as I want send it in one lump char message; // reverse the byte order of everything int time = htonl(currentTime); float LAT = htonl((float)AC_Lat); double LONG = htonl(AC_Long); unsigned int ALT = htonl(AC_Alt); // Copy it all to message memcpy(&message,&time, 4 ); memcpy(&message,&LAT, 4 ); memcpy(&message,&LONG, 8 ); memcpy(&message,&ALT, 4 ); // I use this for testing purposes to check the contents of LAT, before the conversion it is 51.274999999, after the conversion it is 51! float tlat = 0; memcpy(&tlat,&message, 4 ); tlat = htonl(tlat); // this is my function that send it broadcastMessage(message,20); int time; float LAT; double LONG; unsigned int ALT
I can send the data just fine but get garbage out the other end.
I would appreciate any help available; I’m fully open to a re-write as I think I’m barking up the wrong tree here!
Edited 3 Years Ago by Alexkid: format