title: Receiving large binary data over Boost::Beast websocket
body: <p>I am trying to receive a large amount of data using a boost::beast::websocket, fed by another boost::beast::websocket. Normally, this data is sent to a connected browser but I'd like to set up a purely C++ unit test validating certain components of the traffic. I set the auto fragmentation to true from the sender with a max size of 1MB but after a few messages, the receiver spits out:</p>
  <pre><code>Read 258028 bytes of binary
  Read 1547176 bytes of binary
  Read 168188 bytes of binary
  &quot;Failed read: The WebSocket message exceeded the locally configured limit&quot;
  </code></pre>
  <p>Now, I should have no expectation that a fully developed and well supported browser should exhibit the same characteristics as my possibly poorly architected unit test, which it does not. The browser has no issue reading 25MB messages over the websocket. My boost::beast::websocket on the other hand hits a limit.</p>
  <p>So before I go down a rabbit hole, I'd like to see if anyone has any thoughts on this. My read sections looks like this:</p>
  <pre><code>void on_read(boost::system::error_code ec, std::size_t bytes_transferred)
  {
      boost::ignore_unused(bytes_transferred);
  
      if (ec)
      {
          m_log.error(&quot;Failed read: &quot; + ec.message());
          // Stop the websocket
          stop();
          return;
      }
  
      std::string data(boost::beast::buffers_to_string(m_buffer.data()));
  
      // Yes I know this looks dangerous. The sender always sends as binary but occasionally sends JSON 
      if (data.at(0) == '{')
          m_log.debug(&quot;Got message: &quot; + data);
      else
          m_log.debug(&quot;Read &quot; + utility::to_string(m_buffer.data().buffer_bytes()) + &quot; of binary data&quot;);
  
      // Do the things with the incoming doata
      for (auto&amp;&amp; callback : m_read_callbacks)
          callback(data);
  
      // Toss the data
      m_buffer.consume(bytes_transferred);
  
      // Wait for some more data
      m_websocket.async_read(
          m_buffer,
          std::bind(
              &amp;WebsocketClient::on_read,
              shared_from_this(),
              std::placeholders::_1,
              std::placeholders::_2));
  }
  </code></pre>
  <p>I saw in a separate example that instead of doing an async read, you can do a for/while loop reading some data until the message is done (<a href="https://www.boost.org/doc/libs/1_67_0/libs/beast/doc/html/beast/using_websocket/send_and_receive_messages.html" rel="nofollow noreferrer">https://www.boost.org/doc/libs/1_67_0/libs/beast/doc/html/beast/using_websocket/send_and_receive_messages.html</a>). Would this be the right approach for an always open websocket that could send some pretty massive messages? Would I have to send some indicator to the client that the message is indeed done? And would I run into the exceeded buffer limit issue using this approach?</p>