Boost.Asio C++ Network Programming by Boost.Asio C++ Network Programming by John Torjo

Boost.Asio C++ Network Programming by Boost.Asio C++ Network Programming by John Torjo

Author:Boost.Asio C++ Network Programming by John Torjo
Language: eng
Format: epub
Publisher: Packt Publishing


The preceding code snippet will generate the following code:

server echoed our John says hi: OK server echoed our so does James: OK server echoed our Lucy just got home: OK

TCP asynchronous server

The core functionality is similar to the one from the asynchronous client, shown as follows:

class talk_to_client : public boost::enable_shared_from_this<talk_to_client> , boost::noncopyable { typedef talk_to_client self_type; talk_to_client() : sock_(service), started_(false) {} public: typedef boost::system::error_code error_code; typedef boost::shared_ptr<talk_to_client> ptr; void start() { started_ = true; do_read(); } static ptr new_() { ptr new_(new talk_to_client); return new_; } void stop() { if ( !started_) return; started_ = false; sock_.close(); } ip::tcp::socket & sock() { return sock_;} ... private: ip::tcp::socket sock_; enum { max_msg = 1024 }; char read_buffer_[max_msg]; char write_buffer_[max_msg]; bool started_; };



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.