- server.cpp
- read message from client and write message to client
- clent.cpp
- read message from server and write data to server
- ioservice1
- test async_wait with multil thread
g++ server.cpp -o server -lpthread
g++ client.cpp -o client -lpthread
g++ thread.cpp -o thread -lpthread
./server
open other terminal
./client
tcp::resolver::query q{"127.0.0.1", "2014"};
resolv.async_resolve(q, resolve_handler);
ioservice.run();
- resolve_handler: call asyn_connect()
- connect handler: call async_read(), async_write(), write()
- read_handler: cout.write <<
- io_service ioservice;
- tcp::resolver resolv{ioservice};
- tcp::socket tcp_socket{ioservice};
- tcp_acceptor.listen();
- tcp_acceptor.async_accept(tcp_socket, accept_handler);
- ioservice.run();
- accept_handler: call async_read(), async_write()
- read_handler: cout.write <<
- io_service ioservice;
- tcp::endpoint tcp_endpoint{tcp::v4(), 2014};
- tcp::acceptor tcp_acceptor{ioservice, tcp_endpoint};
- tcp::socket tcp_socket{ioservice};
https://theboostcpplibraries.com/boost.asio-network-programming