Boost.Asio C++ Network Programming Cookbook

Book description

Over 25 hands-on recipes to create robust and highly-efficient cross-platform distributed applications with the Boost.Asio library

About This Book
  • Build highly efficient distributed applications with ease
  • Enhance your cross-platform network programming skills with one of the most reputable C++ libraries
  • Find solutions to real-world problems related to network programming with ready-to-use recipes using this detailed and practical handbook
Who This Book Is For

If you want to enhance your C++ network programming skills using the Boost.Asio library and understand the theory behind development of distributed applications, this book is just what you need. The prerequisite for this book is experience with general C++11. To get the most from the book and comprehend advanced topics, you will need some background experience in multithreading.

What You Will Learn
  • Boost your working knowledge of one of the most reputable C++ networking libraries - Boost.Asio
  • Familiarize yourself with the basics of TCP and UDP protocols
  • Create scalable and highly-efficient client and server applications
  • Understand the theory behind development of distributed applications
  • Increase the security of your distributed applications by adding SSL support
  • Implement a HTTP client easily
  • Use iostreams, scatter-gather buffers, and timers
In Detail

Starting with recipes demonstrating the execution of basic Boost.Asio operations, the book goes on to provide ready-to-use implementations of client and server applications from simple synchronous ones to powerful multithreaded scalable solutions. Finally, you are presented with advanced topics such as implementing a chat application, implementing an HTTP client, and adding SSL support. All the samples presented in the book are ready to be used in real projects just out of the box.

As well as excellent practical examples, the book also includes extended supportive theoretical material on distributed application design and construction.

Style and approach

This book is a set of recipes, each containing the statement and description of a particular practical problem followed by code sample providing the solution to the problem and detailed step-by-step explanation. Recipes are grouped by topic into chapters and ordered by the level of complexity from basic to advanced.

Table of contents

  1. Boost.Asio C++ Network Programming Cookbook
    1. Table of Contents
    2. Boost.Asio C++ Network Programming Cookbook
    3. Credits
    4. About the Author
    5. About the Reviewer
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Sections
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      5. Conventions
      6. Reader feedback
      7. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. The Basics
      1. Introduction
      2. Creating an endpoint
        1. Getting ready
        2. How to do it…
          1. Creating an endpoint in the client to designate the server
          2. Creating the server endpoint
        3. How it works…
        4. There's more...
        5. See also
      3. Creating an active socket
        1. How to do it...
        2. How it works...
        3. There's more...
        4. See also
      4. Creating a passive socket
        1. How to do it…
        2. How it works…
        3. See also
      5. Resolving a DNS name
        1. How to do it…
        2. How it works…
        3. There's more…
        4. See also
      6. Binding a socket to an endpoint
        1. How to do it…
        2. How it works…
        3. There's more…
        4. See also
      7. Connecting a socket
        1. How to do it…
        2. How it works…
        3. There's more…
        4. See also
      8. Accepting connections
        1. How to do it…
        2. How it works…
        3. See also
    9. 2. I/O Operations
      1. Introduction
        1. I/O buffers
        2. Synchronous and asynchronous I/O operations
        3. Additional operations
      2. Using fixed length I/O buffers
        1. How to do it…
          1. Preparing a buffer for an output operation
          2. Preparing a buffer for an input operation
        2. How it works…
          1. Preparing a buffer for an output operation
          2. Preparing a buffer for an input operation
        3. See also
      3. Using extensible stream-oriented I/O buffers
        1. How to do it…
        2. How it works…
        3. See also
      4. Writing to a TCP socket synchronously
        1. How to do it…
        2. How it works…
          1. Alternative – the send() method
        3. There's more...
        4. See also
      5. Reading from a TCP socket synchronously
        1. How to do it…
        2. How it works…
          1. Alternative – the receive() method
        3. There's more...
          1. The asio::read() function
          2. The asio::read_until() function
          3. The asio::read_at() function
        4. See also
      6. Writing to a TCP socket asynchronously
        1. How to do it…
        2. How it works…
        3. There's more...
        4. See also
      7. Reading from a TCP socket asynchronously
        1. How to do it…
        2. How it works…
        3. There's more...
        4. See also
      8. Canceling asynchronous operations
        1. How to do it…
        2. How it works…
        3. There's more...
        4. See also
      9. Shutting down and closing a socket
        1. How to do it…
          1. The client application
          2. The server application
          3. Closing a socket
        2. How it works…
        3. See also
    10. 3. Implementing Client Applications
      1. Introduction
        1. The classification of client applications
        2. Synchronous versus asynchronous
        3. The sample protocol
      2. Implementing a synchronous TCP client
        1. How to do it…
        2. How it works…
          1. The SyncTCPClient class
          2. The main() entry point function
        3. See also
      3. Implementing a synchronous UDP client
        1. How to do it…
        2. How it works…
          1. The SyncUDPClient class
          2. The main() entry point function
        3. See also
      4. Implementing an asynchronous TCP client
        1. How to do it…
        2. How it works…
          1. Starting the application – the main() entry point function
          2. Request completion – the handler() callback function
          3. The AsyncTCPClient class – initializing
          4. The AsyncTCPClient class – initiating a request
          5. The AsyncTCPClient class – canceling the request
          6. The AsyncTCPClient class – closing the client
        3. There's more…
          1. Implementing a multithreaded TCP client application
        4. See also
    11. 4. Implementing Server Applications
      1. Introduction
        1. The sample protocol
      2. Implementing a synchronous iterative TCP server
        1. How to do it…
        2. How it works…
          1. The Service class
          2. The Acceptor class
          3. The Server class
          4. The main() entry point function
          5. Eliminating the drawbacks
            1. Stopping a server in reasonable amount of time
            2. Dealing with the server's vulnerability
          6. Analyzing the results
        3. See also
      3. Implementing a synchronous parallel TCP server
        1. How to do it…
        2. How it works…
          1. The Service class
          2. The Acceptor class
          3. The Server class
          4. The main() entry point function
          5. Eliminating the drawbacks
        3. See also
      4. Implementing an asynchronous TCP server
        1. How to do it…
        2. How it works…
          1. The Service class
          2. The Acceptor class
          3. The Server class
          4. The main() entry point function
        3. See also
    12. 5. HTTP and SSL/TLS
      1. Introduction
      2. Implementing the HTTP client application
        1. How to do it…
          1. The HTTPResponse class
          2. The HTTPRequest class
          3. The HTTPClient class
          4. The callback and the main() entry point function
        2. How it works…
          1. The HTTPClient class
          2. The HTTPRequest class
          3. The HTTPResponse class
          4. Callback and the main() entry point functions
        3. See also
      3. Implementing the HTTP server application
        1. Getting ready…
        2. How to do it…
        3. How it works…
        4. See also
      4. Adding SSL/TLS support to client applications
        1. Getting ready…
        2. How to do it…
        3. How it works…
          1. The SyncSSLClient class
          2. The main() entry point function
        4. See also
      5. Adding SSL/TLS support to server applications
        1. Getting ready…
        2. How to do it…
        3. How it works…
          1. The Service class
          2. The Acceptor class
        4. See also
    13. 6. Other Topics
      1. Introduction
      2. Using composite buffers for scatter/gather operations
        1. Getting ready…
        2. How to do it…
          1. Preparing a composite buffer for gather output operations
          2. Preparing a composite buffer for an input operation
        3. How it works…
        4. See also
      3. Using timers
        1. How to do it…
        2. How it works…
      4. Getting and setting socket options
        1. Getting ready…
        2. How to do it…
        3. How it works…
      5. Performing a stream-based I/O
        1. How to do it…
        2. How it works…
        3. There's more…
          1. Implementing a server-side I/O
          2. Setting timeout intervals
    14. Index

Product information

  • Title: Boost.Asio C++ Network Programming Cookbook
  • Author(s): Dmytro Radchuk
  • Release date: January 2016
  • Publisher(s): Packt Publishing
  • ISBN: 9781783986545