1
votes

I'm learning to use Boost::Asio

I was wondering : when should I use read_until ? When should I use read ?

Is it better to specify the length of your data in a header at the beginning of your data buffer OR to use a delimiter with read_until ?

1

1 Answers

4
votes

One is not better than the other.

You use what your protocol requires.

Typically

  • binary protocols specify the packet length up front (by sending it first)

  • text protocols tend to structure information using delimiters (like { ... } for JSON like grammars, or \r\n for SMTP/HTTP etc).

Naturally you'd use read_until for the latter