Book Image

Boost.Asio C++ Network Programming

By : Wisnu Anggoro
Book Image

Boost.Asio C++ Network Programming

By: Wisnu Anggoro

Overview of this book

Table of Contents (15 chapters)
Boost.Asio C++ Network Programming Second Edition
Credits
About the Authors
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Network applications were not very easy to develop about two decades ago. But thanks to Boost.Asio, which has provided us with the network programming function as well as the asynchronous operations functionality to program a network application, we can now develop them easily. Since data transmission over a network can take a long time, which means acknowledgments and errors may not be available as fast as the functions that send or receive data can execute, the asynchronous operations functionality is really required in network application programming. In this book, you will learn the basics of networking and also how to develop a network application using the Boost.Asio libraries.

What this book covers

Chapter 1, Simplifying Your Network Programming in C++, explains the preparation of a C++ compiler, which will be used to compile all the source code in this book. Also, it will tell us how to compile a single source code and link to multiple source codes.

Chapter 2, Understanding the Networking Concepts, covers the network reference models, which are OSI and TCP/IP. It also provides various TCP/IP tools that we will often be using to detect whether an error has occurred in our network connection.

Chapter 3, Introducing the Boost C++ Libraries, explains how to set up the compiler in order to compile the code that contains the Boost libraries and how to build the binaries of libraries that we have to compile separately.

Chapter 4, Getting Started with Boost.Asio, talks about concurrent and nonconcurrent programming. It also discusses the I/O service, which is used to access the operating system's resources and establish communication between our program and the operating system that performs I/O requests.

Chapter 5, Delving into the Boost.Asio Library, walks us through how to serialize an I/O service's work in order to ensure that the order of work completely matches the order we have designed. It also covers how to handle errors and exceptions and create time delays in network programming.

Chapter 6, Creating a Client-server Application, discusses developing a server that is able to send and receive data traffic from a client and also how to create a client-side program to receive data traffic.

Chapter 7, Debugging the Code and Solving the Error, covers the debugging process to trace the errors that may be produced by an unexpected result, such as getting crash in the middle of a program execution. After reading this chapter, you will be able to solve various errors by debugging the code.

What you need for this book

To walk through this book and to successfully compile all source codes, you need a personal computer that runs Microsoft Windows 8.1 (or a later version) and contains the following software:

  • MinGW-w64 for Windows, version 4.9.2

  • The latest version of Notepad++

  • The Boost C++ libraries, version 1.58.0

Who this book is for

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

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Wait for a moment until the mingw-w64-install.exe file is completely downloaded."

A block of code is set as follows:

/* rangen.cpp */
#include <cstdlib>
#include <iostream>
#include <ctime>
int main(void) {

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

int guessNumber;
std::cout << "Select number among 0 to 10: ";
std::cin >> guessNumber;

Any command-line input or output is written as follows:

rundll32.exe sysdm.cpl,EditEnvironmentVariables

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "You will be greeted by a Welcoming dialog box. Just press the Next button to go to the Setup Setting dialog box."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.