title: boost::asio::read function hanging
body: <p>If someone could please help me out, I cannot understand how the boost::asio::read function works in boost asio.  In boost's example they have it declare the buffer size before the message is received which makes no sense (how do I know how many bytes to read before I read the message?)</p>
  
  <p>I tried this code but it just hangs</p>
  
  <pre><code>  boost::asio::io_service io_service;
  
    tcp::resolver resolver(io_service);
    tcp::resolver::query query(tcp::v4(), "localhost", "3000");
    tcp::resolver::iterator iterator = resolver.resolve(query);
  
    tcp::socket sock(io_service);
    boost::asio::connect(sock, iterator);
    cout &lt;&lt; "read start" &lt;&lt; endl;
    boost::system::error_code err_code;
  
    // Read from client.
    boost::asio::streambuf read_buffer;
    int bytes_transferred = boost::asio::read(sock, read_buffer, err_code);
    std::cout &lt;&lt; "Read: " &lt;&lt; make_string(read_buffer) &lt;&lt; std::endl;
    read_buffer.consume(bytes_transferred); // Remove data that was read.
  </code></pre>