【发布时间】:2014-06-20 01:09:15
【问题描述】:
我正在学习 boost asio 并且有错误。我编写了简单的客户端(我可以从它发送数据,但是当我读取数据时我什至无法编译它)我使用协议缓冲区来序列化数据。所以文件#include "test.pb.h" 是probuffer 类
我的代码客户端:
#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)
{
try
{
// connect to the 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; // this will hold serialized data
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 by peer.
// std::cout << data.size() << std::endl; // shows a reduction in amount of
remaining data
// boost::asio::read(socket, boost::asio::buffer(data) /*,
}
boost::asio::transfer_exactly(65536) */);
}
catch (std::exception& e)
{
//std::cerr << e.what(luuu) << std::endl;
}
std::cout << "\nClosing";
std::string dummy;
}
我不明白的错误代码: 错误 C2679:二进制“=”:未找到采用“const boost::asio::const_buffer”类型的右侧操作数的运算符(或没有可接受的转换) 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> 在尝试匹配参数列表时 '(boost::asio::mutable_buffer, const boost::asio::const_buffer)'
【问题讨论】:
-
你为什么不发布一个语法错误稍微少一点的示例?您的编译器永远不会编译您在问题中显示的代码。
标签: boost client boost-asio