How can I retrieve null-terminated string from a socket using the boost::asio library?
m_socket = boost::asio::ip::tcp::socket(io_service);
boost::asio::streambuf replyBuf;
...
...
boost::asio::read_until(m_socket, replyBuf, '\0');
And if you want to transform the streambuf to a string:
std::string retVal((std::istreambuf_iterator<char>(&replyBuf)),
std::istreambuf_iterator<char>());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With