I have one tcp client that need read data via tcp
but i need read one tcp packet data at each time.
I usethis code:
socket_[socket_index]->async_receive(
boost::asio::buffer(buf, max_size),
boost::bind(
&pipe::handle_read, shared_from_this(),
boost::asio::placeholders::error,
socket_index,
boost::asio::placeholders::bytes_transferred));
but sometime I read more than one packet.how I need change it to read only one packet data?
You just can’t. You have your networking concepts confused, TCP is higher-level than that.
Use UDP if you really need to manipulate individual packets. For your minimal case, it’s easy to switch.