I\'m using Boost.Asio for a server application that I\'m writing.
async_send
requires the caller to keep ownership of the data that is being sent until
The way that I've been doing it is to really take the "TCP is a stream" concept to heart. So I have a boost::asio::streambuf
for each connection to represent what I send to the client.
Like most of the examples in boost, I have a tcp_connection
class with an object per connection. Each one has a memeber boost::asio::streambuf response_;
and when I want to send something to the client I just do this:
std::ostream responce_stream(&response_);
responce_stream << "whatever my responce message happens to be!\r\n";
boost::asio::async_write(
socket_,
response_,
boost::bind(
&tcp_connection::handle_write,
shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));