![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Dec 2006
Posts: 9
Rep Power: 0
![]() |
Hi, I have a situation where I've got some programs communicating via sockets. They can only send strings to each other.
so if I try this: c++ Syntax (Toggle Plain Text)
Essentially i can only send a string and have two processes of the same program sending and reciving the same struct, so the structure of the memory will be preserved. can someone suggest a way to efficiently do this and it should work for zero values in arrays and integers. Thanks a lot in advance prototype_angel |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Nov 2007
Posts: 33
Rep Power: 0
![]() |
Re: how to encode a struct in a string for communication (c++)(pointers)
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Dec 2006
Posts: 9
Rep Power: 0
![]() |
Re: how to encode a struct in a string for communication (c++)(pointers)
That was useful. thanks.
|
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
Re: how to encode a struct in a string for communication (c++)(pointers)
You can also use Boost.Serialization. It will handle all that work for you. Its lets you chose text, binary, or xml output. If you are on windows, you can get installers for boost here. See the tutorial, it will help you write a simple to way serialization function. You will then be able to dump the struct to a string and build the struct back from the string.
Its text format will help you avoid endian and struct data member alignment issues which you appear to be ignoring here.
__________________
Robotics @ Maryland AUV Team - Software Lead |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| An Attempt at a DBMS | grimpirate | PHP | 8 | Apr 17th, 2007 2:01 PM |
| Throwing an exception when using string constructor | csrocker101 | C# | 3 | Apr 8th, 2007 3:04 PM |
| how to use pointers to display a part of a string | rahulsr123 | C++ | 10 | Feb 15th, 2006 6:46 PM |
| Pointers in C (Part II) | Stack Overflow | C | 2 | Apr 29th, 2005 11:39 AM |
| Pointers in C (Part I) | Stack Overflow | C | 4 | Apr 28th, 2005 8:03 PM |