diff --git a/message.cpp b/message.cpp index a2cf025..d3ab141 100644 --- a/message.cpp +++ b/message.cpp @@ -8,8 +8,7 @@ void message::send(boost::asio::ip::tcp::socket& socket) { system::error_code ec; - asio::write(socket, asio::buffer(get_message_length()), ec); - asio::write(socket, asio::buffer(get_message()), ec); + asio::write(socket, asio::buffer(get_message_length() + get_message()), ec); if (ec) throw std::runtime_error("Networking error: " + ec.message()); @@ -28,8 +27,9 @@ void message::receive(boost::asio::ip::tcp::socket& socket) asio::read(socket, sb, asio::transfer_exactly(len), ec); data.clear(); + data.reserve(len); is.clear(); - is >> data; + data = std::string(std::istreambuf_iterator(is), std::istreambuf_iterator()); if (ec) throw std::runtime_error("Networking error: " + ec.message());