title: Sending a Mat object over socket from c++ to Java
body: <p>I'm interested on sending a video stream from a C++ server to a Java client. The C++ server is written with boost/asio.
  <br/>
  I was thinking of using opencv in order to easily connect to a computer's usb camera. However, I'm having troubles with sending Mat object over socket.</p>
  
  <p>The only way ,that I encountered, to do so is this way:</p>
  
  <pre><code>Mat frame;
  ...
  int  imgSize = frame.total()*frame.elemSize();
  bytes = send(clientSock, frame.data, imgSize, 0))
  </code></pre>
  
  <p>but I cannot send it with boost this way, since it has to be in one of these forms:
  <a href="http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference/basic_raw_socket/send_to.html" rel="nofollow">http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference/basic_raw_socket/send_to.html</a></p>
  
  <p>So I thought of converting frame.data ,imgSize to string, and sending a container of these two buffers, but I don't think this is the right way. And even if it is, how can I "rebuild" the image in the Java client?</p>
  
  <p>Any idea would be appreciated!</p>