I have a question about sending data in UDP.
For example i have this structure :
structure NetworkPacket
{
char *m_data;
int m_id;
};
And i fill it like this :
SomeStructure l_data; ... NetworkPacket l_packet; l_packet.m_data = (char*)(&l_data); l_packet.m_id = 1;
And send it / receive it like this
sendto(socket, (char*)(&l_packet), sizeof(NetworkPacket), 0, (sockaddr*)&address, sizeof(sockaddr)); NetworkPacket l_packet; auto l_bytes_received = 0; l_bytes_received = recvfrom(socket, (char*)(&l_packet), sizeof(NetworkPacket), 0, (sockaddr*)&l_incomingAddress, &l_size)
Is it true that this will fail because in the structure NetworkPacket the char * is dynamic so it's size isn't known in the structure declaration?
Also i had an idea about solving it if the above is true.
What about just sending a packet with the size of the packet that will come next in it?
But this will fail if the packets got reordered somewhere. Does that happen often in UDP?
If so then this design isn't really good, and if it doesn't should i just ignore that and send the packets again that where lost?
Thanks in advance.






