Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
c++ - How to serialize to binary data for TCP/IP communication
Hy! I am searching a tutorial which shows me how I can serailia a C++ class to binary data to send it over the network and deserialze it at the receiver. Does anyone have an example or link? Ronny Jan 24 2007
Masterchief skrev:Hy! I am searching a tutorial which shows me how I can serailia a C++ class to binary data to send it over the network and deserialze it at the receiver. Does anyone have an example or link? Jan 24 2007
HY! I tried your suggestion with the cast to void*. I did this a few days ago, but it failed. But with your hint I could figure out my error. I had a char* in my Message class and this caused the error, should mean the class was not correct assembled at recv. IŽhave changed it now to the following members: class BaseMessage : public DynamicListElement { public: enum MessageType { NO_MSG = 0, BASE_MSG, UNDEF_MSG }; BaseMessage(); ~BaseMessage(); <SNIP> private: //char* mData; BaseMessageItemList mList; char mHeader[MESSAGE_HEADER_LENGTH]; static unsigned long mMessageId; unsigned long mDataLen; unsigned long mAnswerId; //char* mSender; //struct hostent mSender; char mSender[256]; MessageType mType; }; BaseMessageItemList is an array of 20 BaseMessageItem s. Send is done the following way: BaseMessage *lMess = new BaseMessage(); BaseMessageItem it2; it2.setId(333); lMess->addElement(it2); int ret = send(mSocket, (const char*)(void*)lMess, lSize, MSG_DONTROUTE); Recv is done the following: BaseMessage* lRecvMes = new BaseMessage(); int rlen = recv(piSocket, (char*)(void*)lRecvMes, sizeof(BaseMessage), 0); My question now is can I change the BaseMessageItemList to a pointered List? YouŽll quess IŽve already tryed it and it didnŽt work:-( Do you have any suggestions? Thanks "Bertel Brander" <bertel post4.tele.dk> schrieb im Newsbeitrag news:ep8mfp$e4l$1 digitaldaemon.com...Masterchief skrev:Hy! I am searching a tutorial which shows me how I can serailia a C++ class to binary data to send it over the network and deserialze it at the receiver. Does anyone have an example or link? Jan 25 2007
Masterchief skrev:HY! I tried your suggestion with the cast to void*. I did this a few days ago, but it failed. But with your hint I could figure out my error. I had a char* in my Message class and this caused the error, should mean the class was not correct assembled at recv. IŽhave changed it now to the following members: class BaseMessage : public DynamicListElement { public: enum MessageType { NO_MSG = 0, BASE_MSG, UNDEF_MSG }; BaseMessage(); ~BaseMessage(); <SNIP> private: //char* mData; BaseMessageItemList mList; char mHeader[MESSAGE_HEADER_LENGTH]; static unsigned long mMessageId; unsigned long mDataLen; unsigned long mAnswerId; //char* mSender; //struct hostent mSender; char mSender[256]; MessageType mType; }; BaseMessageItemList is an array of 20 BaseMessageItem s. Send is done the following way: BaseMessage *lMess = new BaseMessage(); BaseMessageItem it2; it2.setId(333); lMess->addElement(it2); int ret = send(mSocket, (const char*)(void*)lMess, lSize, MSG_DONTROUTE); Recv is done the following: BaseMessage* lRecvMes = new BaseMessage(); int rlen = recv(piSocket, (char*)(void*)lRecvMes, sizeof(BaseMessage), 0); My question now is can I change the BaseMessageItemList to a pointered List? YouŽll quess IŽve already tryed it and it didnŽt work:-( Do you have any suggestions? Jan 25 2007
Hy! <SNIP>My question now is can I change the BaseMessageItemList to a pointered List? YouŽll quess IŽve already tryed it and it didnŽt work:-( Do you have any suggestions? Jan 25 2007
Masterchief skrev:Hy! <SNIP>My question now is can I change the BaseMessageItemList to a pointered List? YouŽll quess IŽve already tryed it and it didnŽt work:-( Do you have any suggestions? Jan 27 2007
Thanks a lot! "Bertel Brander" <bertel post4.tele.dk> schrieb im Newsbeitrag news:epgk1l$2ivg$1 digitaldaemon.com...Masterchief skrev:Hy! <SNIP>My question now is can I change the BaseMessageItemList to a pointered List? YouŽll quess IŽve already tryed it and it didnŽt work:-( Do you have any suggestions? Jan 28 2007
|