creating and sending a UDP packet, datatype conversion, C++ pseudocode example
uint16 magicNumber = 0x6001;
char version[4] = [3,1,0,0];
uint16 future = 0;
uint32 dataSizeTmp;
char eventMask[30]; // [0xff, 0xff, 0xc3, …..] created elsewhere
float data[120]; // [1.5434, 2.4556, 3.4863…..] created elsewhere
char outBuffer[1024];
void sendNetworkData() {
magicNumber = htons(magicNumber);
memcpy(&outBuffer[totalLength], &magicNumber, sizeof(magicNumber)); // set magic number
totalLength+=sizeof(magicNumber);
memcpy(&outBuffer[totalLength], &version, sizeof(version)); // set version
totalLength+=sizeof(version);
memcpy(&outBuffer[totalLength], &future, sizeof(future)); // set future use int
totalLength+=sizeof(future);
memcpy(&outBuffer[totalLength], eventMask, EVENT_MASK_LENGTH); // Set event mask
totalLength+=EVENT_MASK_LENGTH;
dataSizeTmp = htonl(dataSize); // read and set dataSize
memcpy(&outBuffer[totalLength], &dataSizeTmp, sizeof(dataSizeTmp));
totalLength+=sizeof(dataSize);
memcpy(&outBuffer[totalLength], data, dataSize); // set data
networkPort->SendBuffer(outBuffer, NET_OUT_BUF_SIZE); // send buffer
}