asio writing asynchronous server (C ++ asio library network related)

enable_shared_from_this: where represents the class methods themselves need to be packaged into smart pointer
using pointer = boost :: shared_ptr <tcp_connection > equivalent typedef boost :: shared_ptr <tcp_connection> pointer
along the following lines to generate two kinds of smart pointers, a first return memory assigned twice, the second can not be used in some places, such as the meaning of words became a private constructor type
Here Insert Picture Description
by async_write write data, handle_write callback function to prevent failure by shard_from_this class
calls itself lambda function pointer can move to improve efficiency may be passed directly copy the value of the value

Callback after successful connection: handle_accept

start_accept () new client connections

Asio asynchronous server on the following complete code:
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Published 137 original articles · won praise 33 · views 1561

Guess you like

Origin blog.csdn.net/qq_39885372/article/details/104069529