I'm trying to get a packet from the client with boost::asio::async_read_until..
boost::asio::async_read_until(socket, buf, 0x78, boost::bind(&Session::ReadHandler, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
The client send FE 42 54 89 7B 14 05 78 FE 42 55 89 7B 14 05 78 and with async_read_until i got FE 42 54 89 7B 14 05 78. Now, how can i get the second part of packet ? in some cases, the client concatenate 2 or more packets in one before of send to server..
I hope this is possible, thanks in advanced !
Edit 1 My Code
boost::asio::ip::tcp::socket socket;
boost::asio::streambuf buf;
void Session::Read()
{
boost::asio::async_read_until(socket, buf, 0x78, boost::bind(&Session::ReadHandler, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
}
void Session::ReadHandler(const boost::system::error_code &error, std::size_t bytes_transferred)
{
if (!error)
{
boost::asio::streambuf::const_buffers_type data = buf.data();
std::string packet(boost::asio::buffers_begin(data), boost::asio::buffers_end(data));
buf.consume(buf.size());
}
else
{
socket.close();
}
}