Looking at the information of the Boost.asio Library of the day, it is still a little confused. For ASIO's study to continue, at the same time here also recorded the first small example of their own start. It feels better to start with a small example and then to understand what those principles are. Because the conceptual principle is too abstract, with a small example to know how to be a routine. For the ASIO library in the later study will continue to write some articles to record some notes.
(Note: I am not a professional internet person, some things may be my own understanding is very naïve, there is no way I even know the TCP/IP protocol very little.) Can only learn to understand the side. )
(1) server-side code
#include <iostream>#include<boost/asio.hpp>intMainintargcChar*argv[]) {Boost::asio::io_service service; Boost::asio::ip::tcp::acceptor Acceptor (Service,boost::asio::ip::tcp::endpoint (BOOST::ASIO::IP::TCP::V4 (), the)); BOOLis_stop=false; while(!is_stop) {Boost::asio::ip::tcp::socket sock (service); Acceptor.accept (sock); Std::cout<<sock.remote_endpoint (). Address () <<Std::endl; Boost::system::error_code Errcode; Sock.write_some (Boost::asio::buffer ("Hello World"), Errcode); if(errcode) {std::cout<<boost::system::system_error (Errcode). what () <<Std::endl; Break; } } return 0;}
(2) Code for the client
#include <iostream>#include<boost/asio.hpp>intMainintargcChar*argv[]) {Boost::asio::io_service service; Boost::asio::ip::tcp::acceptor Acceptor (Service,boost::asio::ip::tcp::endpoint (BOOST::ASIO::IP::TCP::V4 (), the)); BOOLis_stop=false; while(!is_stop) {Boost::asio::ip::tcp::socket sock (service); Acceptor.accept (sock); Std::cout<<sock.remote_endpoint (). Address () <<Std::endl; Boost::system::error_code Errcode; Sock.write_some (Boost::asio::buffer ("Hello World"), Errcode); if(errcode) {std::cout<<boost::system::system_error (Errcode). what () <<Std::endl; Break; } } return 0;}
Compile and run results:
Boost note--asio--(1) Simple synchronous communication small sample