views:

223

answers:

1

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

Thanks in advance

+3  A: 
m_socket = boost::asio::ip::tcp::socket(io_service);
boost::asio::streambuf replyBuf;
...
...
boost::asio::read_until(m_socket, replyBuf, nullTerminator);

Where nullTerminator is the nullterminator char (can't input backslash here of some reason). And if you want to transform the streambuf to a string:

std::string retVal((std::istreambuf_iterator<char>(&replyBuf)),
         std::istreambuf_iterator<char>());
Rolle