[SOLVED]Need Help:structure over socket
-
wrote on 3 Nov 2013, 07:29 last edited by
@struct your_structure
{
//variables
},test@When you want to send the structure:
@char * sendPack = (char *)&test;
writeDatagram((const char *)sendPack,sizeof(your_structure),destIP,destPORT);@When you want to receive the packet:
@char recPack[sizeof(your_structure)];
readDatagram((char *)&inPack, sizeof(your_structure),senderIP, senderPort);
your_structure * inp = new your_structure();
inp = (your_structure *)inPack;@ -
wrote on 3 Nov 2013, 15:15 last edited by
[quote author="vahidnateghi" date="1383463791"]@struct your_structure
{
//variables
},test@When you want to send the structure:
@char * sendPack = (char *)&test;
writeDatagram((const char *)sendPack,sizeof(your_structure),destIP,destPORT);@When you want to receive the packet:
@char recPack[sizeof(your_structure)];
readDatagram((char *)&inPack, sizeof(your_structure),senderIP, senderPort);
your_structure * inp = new your_structure();
inp = (your_structure *)inPack;@[/quote]That won't work if you're on different architectures, like trying to communicate between a 32 bits and a 64 bits version of your application, to name just one possible problem with this approach. My advise: never, ever do it this way.
-
wrote on 4 Nov 2013, 05:30 last edited by
[quote author="Andre" date="1383491720"]
That won't work if you're on different architectures, like trying to communicate between a 32 bits and a 64 bits version of your application, to name just one possible problem with this approach. My advise: never, ever do it this way.
[/quote]Yes,you're right, when I used it and it worked, it was between two machines with the same architecture...
21/23