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; }
相关文章推荐
- Boost asio的async_write函数输入日志标题
- boost asio学习笔记 [1] - 同步通讯
- boost_asio学习笔记[2] - 客户端异步通讯
- [网络开发]boost::asio简介
- C++ Boost asio库网络通信 [同/异步] 笔记
- C++ Boost库 asio同步/异步模式[ 定时器来体现 ] 笔记
- Boost::asio io_service
- asio测试
- 用socket(asio)实现了smtp的几个简单的指令
- boost::asio网络传输错误码的一些实验结果(recv error_code )
- 关于boost::asio::read_until()之后再boost::asio::read()可能出现的问题
- boost asio异步通信
- boost::asio 连接管理5
- boost asio 同步阻塞
- asio学习之一:asio下载安装
- asio学习之二:多线程同步回调和访问资源问题
- asio学习之三:asio实现简单的服务器和客户端
- asio.run()的问题
- web socket RFC6455 connection --asio C++11