I have a server that receives a compressed string (compressed with zlib) from a client, and I was using async_receive
from the boost::asio
library
Use async_read_until and create your own match condition, or change your protocol to send a header including the number of bytes to expect in the compressed string.
How were you expecting to do this using any other method?
There are a few general methods to sending data of variable sizes in an async manor:
So can your data be parsed, or a length sent etc...
A single IP packet is limited to an MTU size of ~1500 bytes, and yet still you can download gigabyte-large files from your favourite website, and watch megabyte-sized videos on YouTube.
You need to send a header indicating the actual size of the raw data, and then receive the data by pieces on smaller chunks until you finish receiving all the bytes.
For example, when you download a large file over HTTP, there is a field on the header indicating the size of the file: Content-Length:
.