title: Issue with Boost Sockets
body: <p>First of all I would like to state that I am a beginner at C++ and boost in general, although I do have some experience with languages such as Java and C#.</p>
  
  <p>That being said, I am having a problem when transferring data through Boost TCP sockets. I am using this code:</p>
  
  <p>To Send:</p>
  
  <pre><code>tcp::socket s(io_service);
          boost::asio::connect(s, iterator);
          string response = static_cast&lt;ostringstream*&gt;( &amp;(ostringstream() &lt;&lt; arg1) )-&gt;str() 
              + "," + static_cast&lt;ostringstream*&gt;( &amp;(ostringstream() &lt;&lt; arg2) )-&gt;str()
              + "," + static_cast&lt;ostringstream*&gt;( &amp;(ostringstream() &lt;&lt; arg3) )-&gt;str()
              + "," + static_cast&lt;ostringstream*&gt;( &amp;(ostringstream() &lt;&lt; arg4) )-&gt;str()
              + "," + static_cast&lt;ostringstream*&gt;( &amp;(ostringstream() &lt;&lt; arg5) )-&gt;str()
              + "," + static_cast&lt;ostringstream*&gt;( &amp;(ostringstream() &lt;&lt; arg6) )-&gt;str();
  
          //pad the rest
          while (response.length() &lt; max_length)
          {
              response += ' ';
          }
          boost::asio::write(s, boost::asio::buffer(response, sizeof(response))); 
  </code></pre>
  
  <p>To Read:</p>
  
  <pre><code>tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), port));
      while(true)
      {
          socket_ptr sock(new tcp::socket(io_service));
          a.accept(*sock);
          boost::thread t(boost::bind(session, sock));
      }
  ...
  void session(socket_ptr sock)
  {
      char data[max_length];
      size_t length;
      try
      {
          while(true)
          {           
              boost::system::error_code error;
              //size_t length = sock-&gt;read_some(boost::asio::buffer(data), error);
              length = boost::asio::read(*sock, boost::asio::buffer(data, sizeof data));
              std::cout &lt;&lt; "Length " &lt;&lt; length &lt;&lt; endl;
              if (error == boost::asio::error::eof)
              {
                  break; // Connection closed cleanly by peer.
              }
              else if (error)
              {
                  throw boost::system::system_error(error); // Some other error.
              }
  
          }
      }
      catch (std::exception&amp; e)
      {
          std::cout &lt;&lt; data &lt;&lt; endl;  
          string message = e.what();
          if(std::string::npos != message.find(END_OF_FILE))
          {
              domeSomethingWithTheData(data); 
              memset(data, 0, sizeof data);
          }
          else
          {
              std::cout &lt;&lt; data &lt;&lt;endl;
              std::cerr &lt;&lt; "Exception in thread: " &lt;&lt; e.what() &lt;&lt; "\n";
          }
      }
  }
  </code></pre>
  
  <p>What I cannot understand is that, regardless of what I use, (either <code>boost::asio::read</code> or <code>sock-&gt;read_some</code>), I never get more than 32 characters worth of data. I have tried increasing the size of the buffer to <code>2048</code>, but the issue persisted.</p>
  
  <p>The buffer always contains more than 32 characters (most of which are garbage) but I am assuming that these are not actually being sent from the client but rather come from the actual allocation of the buffer on the server side since <code>std::cout &lt;&lt; "Length " &lt;&lt; length</code> prints out 32.</p>
  
  <p>Any information on how I can, from the client, send an arbitrary amount of characters to the server will be appreciated.</p>
  
  <p>EDIT:</p>
  
  <p>After the pointers provided by Rafal Rawicki, I am now using this code:</p>
  
  <pre><code> boost::asio::streambuf buffer;
      boost::asio::read_until(*sock, buffer, '\n');
      std::istream is(&amp;buffer);
      std::string line;
      std::getline(is, line); 
      std::cout &lt;&lt; line &lt;&lt; std::endl;
  </code></pre>
  
  <p>The client side remained unchanged with the only exception that I am adding a <code>\n</code> at the end. This yields a lot of <code>End of file</code> Exceptions however.</p>