title: Proper use of std::string to send binary data through a socket
body: <p>I'm trying to send files splitted in chunks over a TCP Berkley Socket but i'm getting unexpected behaviors.</p>
  
  <pre><code>std::ifstream inFile (path.c_str(),std::ios::in|std::ios::binary|std::ios::ate); 
  std::streampos _size;
  _size = inFile.tellg();
  char * _buffer = new char [MAXLINE];
  int    _chunk = 0;
  inFile.seekg (0, std::ios::beg);
  
  msg &lt;&lt; "ACK" &lt;&lt; " " &lt;&lt; "START" &lt;&lt; " " &lt;&lt; message[1];
  connTSock-&gt;send_message(msg.str());
  
  while(inFile.read(_buffer , MAXLINE))
  {
     CLEAR_MSG(msg);
     msg &lt;&lt; "ACK" &lt;&lt; " " &lt;&lt; "CHUNK" &lt;&lt; " " &lt;&lt; _chunk &lt;&lt; " " &lt;&lt; _buffer;
     _chunk++;
     connTSock-&gt;send_message(msg.str());
  }
  </code></pre>
  
  <p>In few words I am getting a loss of data , the client opens an output stream and writes in it , but i.e. of 11 kb of the original file i get only 7kb on the other side. I guess that the problem could be related to the fact that I'm pushing the _buffer in a std::stringstream and then converting it in a std::string. 
  Am I right? How could I fix this problem? </p>