You are previewing Boost.Asio C++ Network Programming - Second Edition.
O'Reilly logo
Boost.Asio C++ Network Programming - Second Edition

Book Description

Learn effective C++ network programming with Boost.Asio and become a proficient C++ network programmer

About This Book

  • Learn efficient C++ network programming with minimum coding using Boost.Asio

  • Your one-stop destination to everything related to the Boost.Asio library

  • Explore the fundamentals of networking to choose designs with more examples, and learn the basics of Boost.Asio

  • Who This Book Is For

    This book is for C++ Network programmers with basic knowledge of network programming, but no knowledge of how to use Boost.Asio for network programming.

    What You Will Learn

  • Prepare the tools to simplify network programming in C++ using Boost.Asio

  • Explore the networking concepts of IP addressing, TCP/IP ports and protocols, and LAN topologies

  • Get acquainted with the usage of the Boost libraries

  • Get to know more about the content of Boost.Asio network programming and Asynchronous programming

  • Establish communication between client and server by creating client-server application

  • Understand the various functions inside Boost.Asio C++ libraries to delve into network programming

  • Discover how to debug and run the code successfully

  • In Detail

    Boost.Asio is a C++ library used for network programming operations.

    Organizations use Boost because of its productivity. Use of these high-quality libraries speed up initial development, result in fewer bugs, reduce reinvention-of-the-wheel, and cut long-term maintenance costs. Using Boost libraries gives an organization a head start in adopting new technologies.

    This book will teach you C++ Network programming using synchronous and asynchronous operations in Boost.Asio with minimum code, along with the fundamentals of Boost, server-client applications, debugging, and more.

    You will begin by preparing and setting up the required tools to simplify your network programming in C++ with Boost.Asio. Then you will learn about the basic concepts in networking such as IP addressing, TCP/IP protocols, and LAN with its topologies. This will be followed by an overview of the Boost libraries and their usage.

    Next you will get to know more about Boost.Asio and its concepts related to network programming. We will then go on to create a client-server application, helping you to understand the networking concepts. Moving on, you will discover how to use all the functions inside the Boost.Asio C++ libraries. Lastly, you will understand how to debug the code if there are errors found and will run the code successfully.

    Style and approach

    An example-oriented book to show you the basics of networking and help you create a network application simply using Boost.Asio, with more examples for you to get up and running with Boost.Asio quickly.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the code file.

    Table of Contents

    1. Boost.Asio C++ Network Programming Second Edition
      1. Table of Contents
      2. Boost.Asio C++ Network Programming Second Edition
      3. Credits
      4. About the Authors
      5. Acknowledgements
      6. About the Reviewers
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      8. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      9. 1. Simplifying Your Network Programming in C++
        1. Setting up the MinGW compiler and Text Editor
          1. Installing MinGW-w64
          2. Setting up the Path environment
          3. Choosing and installing the Text Editor
        2. Using the GCC C++ compiler
          1. Compiling a C++ program
          2. Compiling multiple source files
          3. Compiling and linking a program separately
          4. Detecting a warning in the C++ program
        3. Knowing other important options in the GCC C++ compiler
        4. Troubleshooting in the GCC C++ compiler
          1. Help for command-line options
          2. Version numbers
          3. The verbose compilation
        5. Summary
      10. 2. Understanding the Networking Concepts
        1. An introduction to networking systems
          1. The OSI reference model
            1. The Physical layer
            2. The Data Link layer
            3. The Network layer
            4. The Transport layer
            5. The Session layer
            6. The Presentation layer
            7. The Application layer
          2. The TCP/IP reference model
        2. Understanding TCP and UDP
          1. Transmission Control Protocol
          2. User Datagram Protocol
          3. Understanding ports
        3. Exploring the Internet Protocol
          1. Internet Protocol Version 4 – IPv4
          2. Internet Protocol Version 6 – IPv6
        4. Using TCP/IP tools for troubleshooting
          1. The ipconfig command
            1. Displaying the full configuration information
            2. Displaying DNS
            3. Flushing DNS
            4. Renewing the IP address
            5. Releasing the IP address
          2. The ping command
          3. The tracert command
          4. The pathping command
          5. The netstat command
          6. The telnet command
        5. Summary
      11. 3. Introducing the Boost C++ Libraries
        1. Introducing the C++ standard template library
        2. Introducing the Boost C++ libraries
          1. Advantages of Boost libraries
        3. Preparing Boost libraries for the MinGW compiler
          1. Downloading Boost libraries
          2. Deploying Boost libraries
          3. Using Boost libraries
          4. Building Boost libraries
        4. Summary
      12. 4. Getting Started with Boost.Asio
        1. Getting closer to the Boost.Asio library
        2. Examining the I/O service in the Boost.Asio library
          1. Using and blocking the run() function
          2. Using the non-blocking poll() function
          3. Removing the work object
          4. Dealing with many threads
        3. Understanding the Boost.Bind library
          1. Wrapping a function invocation
          2. Working with the Boost.Bind library
          3. Synchronizing data access with the Boost.Mutex library
        4. Giving some work to the I/O service
          1. Using the post() function
          2. Using the dispatch() function
        5. Summary
      13. 5. Delving into the Boost.Asio Library
        1. Serializing the I/O service work
          1. Using the strand function
          2. Wrapping a handler through the strand object
        2. Handling exceptions and errors
          1. Handling an exception
          2. Handling an error
        3. Timing the work execution using the timer class
          1. An expiring timer
          2. Using the timer along with the boost::bind function
          3. Using the timer along with the boost::strand function
        4. Summary
      14. 6. Creating a Client-server Application
        1. Establishing a connection
          1. A synchronous client
          2. An asynchronous client
          3. An asynchronous server
        2. Reading and writing to the socket
          1. The Send() and OnSend() functions
          2. The Recv() and OnRecv() functions
        3. Wrapping the network code
        4. Developing a client and server program
          1. Creating a simple echo server
          2. Creating a simple client program
        5. Summary
      15. 7. Debugging the Code and Solving the Error
        1. Choosing a debugging tool
          1. Installing a debugging tool
          2. Preparing a file for debugging
        2. Running the program under GDB
          1. Starting the debugging process
          2. The continuing and stepping debugging process
          3. Printing the source code
          4. Setting and deleting the breakpoint
          5. Printing a variable value
          6. Modifying a variable value
          7. Calling the command prompt
        3. Solving the error
        4. What's next?
        5. Summary
      16. Index