title: Receiving 0 size messages while using ZMQ and protobuf
body: <p>I am trying to set up a basic communication system between client and server using ZMQ. I am using protobuf for the message format.
  My problem is when I send the message from client the message size is 34 but the message size received  on the server is 0.</p>
  
  <p>Following is my code;</p>
  
  <p>Client.cpp</p>
  
  <pre><code>tutorial::Person person;
  person.set_id(1234);
  person.set_name("john");
  person.set_email("john@mxyz.com");
  person.set_phonenumber("12345678");
  
  
  zmq::context_t context (1); //  Prepare our context and socket
  zmq::socket_t socket (context, ZMQ_PAIR);
  
  std::cout &lt;&lt; "Connecting to server…" &lt;&lt; std::endl;
  int linger = 0;// ms
  socket.setsockopt(ZMQ_LINGER, &amp;linger, sizeof(linger));
  socket.connect ("tcp://127.0.0.1:20000");
  
  std::string msg_str;
  person.SerializeToString(&amp;msg_str);
  std::cout &lt;&lt; "Size of message string is "&lt;&lt; msg_str.size()&lt;&lt;std::endl;
  zmq::message_t request (msg_str.size());
  memcpy ((void *) request.data (), msg_str.c_str(), msg_str.size());
  std::cout &lt;&lt; "Sending Person data ..." &lt;&lt; std::endl;
  socket.send (request);
  
  socket.close();
  
  google::protobuf::ShutdownProtobufLibrary();
  return 0;
  </code></pre>
  
  <p>Server.cpp :</p>
  
  <pre><code>zmq::context_t context(1); //  Prepare our context and socket
  zmq::socket_t socket(context, ZMQ_PAIR);
  int linger = 0; // ms
  socket.setsockopt(ZMQ_LINGER, &amp;linger, sizeof(linger));
  socket.bind("tcp://127.0.0.1:20000");
  while (true)
   {
      zmq::message_t request;
      int recieved = socket.recv(&amp;request);
      std::string msg(static_cast&lt;char*&gt;(request.data()),request.size());
      std::cout&lt;&lt;"Size of message recieved is "&lt;&lt;  msg.size()&lt;&lt;std::endl;
      tutorial::Person person;
      person.ParseFromString(msg);
      std::string text_str1;
      google::protobuf::TextFormat::PrintToString(person, &amp;text_str1);
  }
  socket.close();
  </code></pre>
  
  <p>Output of Client is :</p>
  
  <pre><code>Size of message string is 34
  </code></pre>
  
  <p>Output of server is :</p>
  
  <pre><code>Size of message received is 0
  </code></pre>
  
  <p>I have tried tried switching to ParseToArray also but it did not help.
  Any kind of help is appreciated.</p>