boost asio client

来源:互联网 发布:手机散热软件 编辑:程序博客网 时间:2024/06/05 00:43
#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;}

0 0
原创粉丝点击