send a struct via UDP (Without serialization)
-
wrote on 9 Jun 2016, 07:14 last edited by
Hi,
I have this struct :
typedef struct myStruct { int nb_trame; bool tabBool[20]; } myStruct;
How do I send it via a QUdpSocket (without QDataStream) ?
I thought this will work :
myStruct a; //set 'a' variable mySocket->writeDatagram( (const char*) &a, sizeof(a), someQHostAddress, somePort);
But some people told me it won't..
If possible, i would like to have a code answer x) Because I'm a noob in networking...
I'm using Visual C++ 2010. -
Lifetime Qt Championwrote on 9 Jun 2016, 08:38 last edited by mrjj 6 Sept 2016, 08:47
@Punt said:
QDataStream
Is there a reason you will not use QDataStream ?
It helps you with network details like byte order etc.
What you are doing is very likely to blow up hard
if u send to other pc ( that has different architecture)
and just superimpose(cast) a myStruct over the received data.Normally you would use serialization. :)
-
1/3