Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6948643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:50:59+00:00 2026-05-27T13:50:59+00:00

I’m trying to use this C++ class as a base for my own application’s

  • 0

I’m trying to use this C++ class as a base for my own application’s client/server communication. Client and server both have a ‘person’ class, which I want to serialize:

class person
{
public:
  person()
  {
  }

  person(int age)
    : age_(age)
  {
  }

  int age() const
  {
    return age_;
  }

private:
  friend class boost::serialization::access;

  template <typename Archive>
  void serialize(Archive &ar, const unsigned int version)
  {
    ar & age_;
  }

  int age_;
};

I am trying to serialize and object of it on the server, send that serialization to the client, and create a new object out of it there.

server

while(1)
{
    string clientMessageIn = "";

    // receive from the client

    int numBytes = client->recieveMessage(clientMessageIn);
    if ( numBytes == -99 ) break;

    if(clientMessageIn == "getObject") //Client asked for object
    {
        boost::archive::text_oarchive oa(ss);
        person pi(31); //Create 31 year old person
        oa << pi; //Serialize

        std::string mystring;
        ss >> mystring; //Serialization to string so we can send it

        string sendMsg(mystring); //Set sendMsg (redundant.. probably)
        mystring.clear(); //No longer need mystring
        client->sendMessage(sendMsg); //Send the actual response to the client
        sendMsg.clear(); //Clear
        ss.clear(); //Clear
    }
    else //Client typed something else, just show it
        cout   << "[RECV:" << clientHost << "]: " << clientMessageIn << endl;
}

client

int recvBytes = 0;

while (1)
{
    // send message to server

    char sendmsg[MAX_MSG_LEN+1];
    memset(sendmsg,0,sizeof(sendmsg));
    cout << "[" << localHostName << ":SEND] ";
    cin.getline(sendmsg,MAX_MSG_LEN);

    string sendMsg(sendmsg);
    if ( sendMsg.compare("Bye") == 0 || sendMsg.compare("bye") == 0 ) break;

    myClient.sendMessage(sendMsg);



    // receive response from server

    string clientMessageIn = "";
    recvBytes = myClient.recieveMessage(clientMessageIn);
    if ( recvBytes == -99 ) break;

    //stringstream ss;
    //ss << clientMessageIn; //Server response to ss
    //boost::archive::text_iarchive ia(ss); //This bit is causing the crash

    //person p;
    //ia >> p; //Unserialize

    //ss.clear(); //No longer need the ss contents

    //cout   << "[RECV:" << serverName << "]: " << p.age<< endl; //This doesn't work now
    cout   << "[RECV:" << serverName << "]: " << clientMessageIn << endl;

}

boost::archive::text_iarchive ia(ss); causes the crash; boost::archive::archive_exception at memory location

I had to comment it out, the crash is not suprising. Just look at what the server sends back.

client

As you can see, each time I type getObject, the server sends:

22
serialization::archive
9
0
0
31

And then it starts over. So I guess the application crashes because it’s not receiving the complete serialized object. I also have no idea what most of those numbers are doing there and why they are being sent one by one.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:51:00+00:00Added an answer on May 27, 2026 at 1:51 pm

    As you’ve already pointed out you are not sending the whole serialized data buffer.

        std::string mystring;
        ss >> mystring; //Serialization to string so we can send it
    

    should be turned into

        std::string mystring (ss.str ());
    

    Instead of reading up to the first whitespace we are now storing the entire serialized content in mystring.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
I have this code to decode numeric html entities to the UTF8 equivalent character.
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.