Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think it was just that your receive buffer was not null terminated. This code works:</p> <p>Server:</p> <pre><code>#include &lt;boost/interprocess/ipc/message_queue.hpp&gt; #include &lt;boost/serialization/string.hpp&gt; #include &lt;string&gt; #include &lt;sstream&gt; #include &lt;boost/property_tree/ptree.hpp&gt; #include &lt;boost/property_tree/json_parser.hpp&gt; using boost::interprocess::message_queue; using boost::property_tree::ptree; using boost::property_tree::write_json; #define MAX_SIZE 1000 void send(ptree pt) { std::stringstream oss; write_json(oss,pt); message_queue mq(boost::interprocess::open_or_create,"coda",10,MAX_SIZE); mq.send(oss.str().c_str(), oss.str().size(),0); std::cout &lt;&lt; oss.str() &lt;&lt; std::endl; system("PAUSE"); } int main() { ptree pt; pt.put("prefix","standard"); pt.put("faceID",42); send(pt); } </code></pre> <p>Client:</p> <pre><code>#include &lt;boost/interprocess/ipc/message_queue.hpp&gt; #include &lt;string&gt; #include &lt;strstream&gt; #include &lt;boost/property_tree/ptree.hpp&gt; #include &lt;boost/property_tree/json_parser.hpp&gt; #include &lt;boost/serialization/string.hpp&gt; using boost::interprocess::message_queue; using boost::property_tree::ptree; using boost::property_tree::read_json; #define MAX_SIZE 1000 int main() { message_queue mq (boost::interprocess::open_or_create,"coda",10,MAX_SIZE); size_t recv_size; unsigned int priority; ptree pt; char buffer[MAX_SIZE]; mq.receive(buffer,MAX_SIZE,recv_size,priority); buffer[recv_size] = 0; std::istrstream is(buffer); read_json(is, pt); std::cout &lt;&lt; "prefix: " &lt;&lt; pt.get&lt;std::string&gt;("prefix") &lt;&lt; " -- faceID: " &lt;&lt; pt.get&lt;std::string&gt;("faceID") &lt;&lt; std::endl; system("PAUSE"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload