Reading data with boost asio on client -



Reading data with boost asio on client -

i learning boost asio , have mistake. have written simple client ( can send info when read info cant compile it) used protocol buffer serialize info . file #include "test.pb.h" probuffer class

my code client :

#include <boost/array.hpp> #include <boost/asio.hpp> #include <boost/bind.hpp> #include <boost/foreach.hpp> #include <boost/lexical_cast.hpp> #include <boost/thread/thread.hpp> #include <cstdlib> #include <iostream> #include <string> #include <thread> #include "test.pb.h" using boost::asio::ip::tcp; int main(int argc, char** argv) { seek { // connect server: boost::asio::io_service io_service; tcp::resolver resolver(io_service); std::string const server_address = "localhost"; std::string const server_port = "10000"; tcp::resolver::query query(server_address, server_port); tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); tcp::socket socket(io_service); boost::asio::connect(socket, endpoint_iterator); //while ( true) { person p = person(); p.set_id(22); p.set_name("jack vorobey"); // std::cout << p.id(); // std::cout << p.name(); std::string data; // hold serialized info bool ok = p.serializetostring(&data); assert(ok); // std::cout << data.size() << std::endl; boost::asio::write(socket, boost::asio::buffer(data)) boost::asio::read(socket, boost::asio::buffer(data));; // break; // connection closed cleanly peer. // std::cout << data.size() << std::endl; // shows reduction in amount of remaining info // boost::asio::read(socket, boost::asio::buffer(data) /*, } boost::asio::transfer_exactly(65536) */); } grab (std::exception& e) { //std::cerr << e.what(luuu) << std::endl; } std::cout << "\nclosing"; std::string dummy; }

the code of error dont understand : error c2679: binary '=' : no operator found takes right-hand operand of type 'const boost::asio::const_buffer' (or there no acceptable conversion) 1> c:\local\boost_1_55_0\boost\asio\buffer.hpp(136): 'boost::asio::mutable_buffer &boost::asio::mutable_buffer::operator =(const boost::asio::mutable_buffer &)' 1> while trying match argument list '(boost::asio::mutable_buffer, const boost::asio::const_buffer)'

this because template<typename elem, typename traits, typename allocator> const_buffers_1 buffer(const std::basic_string<elem, traits, allocator> &) returns instance of const_buffers_1 (which model of constbuffersequence concept). certainly, cannot read info constant buffer.

do not read info std::string, because it's not intended (note c_str() , data() fellow member functions homecoming const char*). instead, allocate buffer or utilize asio::streambuf.

boost client boost-asio

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -