O'Reilly logo

Boost.Asio C++ Network Programming by John Torjo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Asynchronous I/O in client applications

The main workflow is somewhat similar to that of the synchronous client applications, with the difference that Boost.Asio sits in between every async_read and async_write requests.

Asynchronous I/O in client applications

The first scenario is what I've implemented as asynchronous client in Chapter 4, Client and Server. Remember that at the end of each asynchronous operation, I start another asynchronous operation, so that the service.run() function doesn't end.

To change this to the second scenario, you'll use the following code snippet:

void on_connect() { do_read(); } void do_read() { async_read(sock_, buffer(read_buffer_), MEM_FN2(read_complete,_1,_2), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required