UDP Datagram to Structure

I am receiving a UDP packet with a structure written in C and it looks like:

[code]struct myStruct
{
uint32_t structID;

uint32_t lastDate;
uint32_t lastTime;

double direction[3];
}[/code]

I managed to receive the datagram and display the data with a UDPSocket. And I defined a structure with the same fields and byte lengths. But how can I add the received data to my (local) struct in xojo?

[code]Dim udpDataGram As DataGram
Dim myStruct As UDPStruct //my defined structure with same fields

udpDataGram = UDPSocket1.Read
TextAreaUDPPacket.Text = d.Data

myStruct = ???[/code]

myStruct.Stringvalue(littleEndian) = udpDataGram.Data

littleEndian is a boolean to tell if the struct is littleEndian or not.
I guess you can use pragmas to check (#TargetLittleEndian)

Hi Massimo

Thank you for the answer. I can compile an run the application and see the data.
But something is strange: first characters seems to be the hostname in udpDataGram.Data. I don’t send the hostname in the data packet. I have to investigate a little bit more (wireshark)

I think this is normal.
See http://ipv6.com/articles/general/User-Datagram-Protocol.htm

FYI: hostname is not included in udpDataGram.Data. Other programmer who wrote the C part under Linux included the hostname without telling me that. :slight_smile:

Thank again for helping.