您的位置:首页 > 其它

boost asio client

2015-10-25 13:05 246 查看
#include <iostream>
#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
using namespace boost::asio::ip;

const int max_length = 1024;
char request_buffer[max_length] = {};
char reply_buffer[max_length] = {};

int main()
{
boost::asio::io_service io_service;
tcp::endpoint end_point(boost::asio::ip::address::from_string("127.0.0.1"), 8888);
tcp::socket tcp_socket(io_service);
tcp_socket.connect(end_point);

for (;;)
{
std::cin.getline(request_buffer, max_length);

size_t request_length = std::strlen(request_buffer);
boost::asio::write(tcp_socket, boost::asio::buffer(request_buffer, request_length));

size_t reply_length = boost::asio::read(tcp_socket, boost::asio::buffer(reply_buffer, request_length));

std::cout.write(reply_buffer, reply_length);
std::cout << "\n";
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  asio