Hi! I'm working with message_queue and want to send a structure to receiver-app. How to serialize i correctly and how to receive it? Here's some sending code: Data data;
data.counter = 9; data.money = 5.4; //data.name = "Guten Tag";
std::stringstream os; // = new std::stringstream; boost::archive::text_oarchive oa(os); oa << data;
ipc::message_queue::remove("mq_main"); ipc::message_queue mq(ipc::create_only, "mq_main", 1, sizeof(std::stringstream)); mq.send(&os, sizeof(os), 0);
I implemented the serializing code in the structure "Data" Add here's my code to receive: Data data;
std::stringstream is; // = new std::stringstream; try { unsigned int priority; ///< The priority ipc::message_queue::size_type recvd_size; ipc::message_queue mq(ipc::open_only, "mq_main");
if(mq.try_receive(&is, sizeof(std::stringstream), recvd_size, priority)) { boost::archive::text_iarchive ai(is); // CRASH ai >> data; } //mq.receive(&is, sizeof(is), recvd_size, priority); //mq.do_receive(ipc::message_queue_t::non_blocking, &is, sizeof(is), recvd_size, priority);
//boost::archive::text_iarchive * ai = new boost::archive::text_iarchive(is);
//*ai >> data;
//data << ai; //mq_recv->receive(&data, sizeof(data), recvd_size, priority);
ipc::message_queue::remove("mq_main"); //is.~basic_stringstream(); } catch(ipc::interprocess_exception &ex) { ipc::message_queue::remove("mq_main"); std::cout << ex.what() << std::endl; return; }
The receiver-app crashes at boost::archive::text_iarchive ai(is). The error is: 0xC0000005: Access violation reading location 0x00f56a34. I really don't have a clue...pls help. Thank you very much :-)