Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++, boost asio, receive null terminated string

How can I retrieve null-terminated string from a socket using the boost::asio library?

like image 946
migajek Avatar asked Oct 07 '09 22:10

migajek


Video Answer


1 Answers

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>());
like image 165
Rolle Avatar answered Oct 12 '22 18:10

Rolle