Reputation: 11
I would like to be able to read, or receive, the entire buffer that was sent to the socket.
Currently, this is my way of receiving data from the server.
std::string Client::Receive()
{
std::string data;
data.resize(1024);
m_sock.receive(boost::asio::buffer(data));
return data;
}
Though if the server sends something larger than 1024 bytes, that won't work. I'd like to overcome this obstacle.
How could I do that?
Thanks a lot!
Upvotes: 0
Views: 262
Reputation: 18
You can use std::stringstream.
https://ru.cppreference.com/w/cpp/io/basic_stringstream
After reading from socket you could use stringstream::str() function to get string from it.
Upvotes: -1
Reputation: 631
Use an std::ostream_iterator
https://en.cppreference.com/w/cpp/iterator/ostream_iterator
It's essentially a pointer that you can just keep writing to, keep in mind you need an actual stream to store it to
Upvotes: -1