Boost.Asio C++ Network Programming Cookbook
Table of Contents
Boost.Asio C++ Network Programming Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Sections
Getting ready
How to do itâŠ
How it worksâŠ
There's moreâŠ
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. The Basics
Introduction
Creating an endpoint
Getting ready
How to do itâŠ
Creating an endpoint in the client to designate the server
Creating the server endpoint
How it worksâŠ
There's more...
See also
Creating an active socket
How to do it...
How it works...
There's more...
See also
Creating a passive socket
How to do itâŠ
How it worksâŠ
See also
Resolving a DNS name
How to do itâŠ
How it worksâŠ
There's moreâŠ
See also
Binding a socket to an endpoint
How to do itâŠ
How it worksâŠ
There's moreâŠ
See also
Connecting a socket
How to do itâŠ
How it worksâŠ
There's moreâŠ
See also
Accepting connections
How to do itâŠ
How it worksâŠ
See also
2. I/O Operations
Introduction
I/O buffers
Synchronous and asynchronous I/O operations
Additional operations
Using fixed length I/O buffers
How to do itâŠ
Preparing a buffer for an output operation
Preparing a buffer for an input operation
How it worksâŠ
Preparing a buffer for an output operation
Preparing a buffer for an input operation
See also
Using extensible stream-oriented I/O buffers
How to do itâŠ
How it worksâŠ
See also
Writing to a TCP socket synchronously
How to do itâŠ
How it worksâŠ
Alternative â the send() method
There's more...
See also
Reading from a TCP socket synchronously
How to do itâŠ
How it worksâŠ
Alternative â the receive() method
There's more...
The asio::read() function
The asio::read_until() function
The asio::read_at() function
See also
Writing to a TCP socket asynchronously
How to do itâŠ
How it worksâŠ
There's more...
See also
Reading from a TCP socket asynchronously
How to do itâŠ
How it worksâŠ
There's more...
See also
Canceling asynchronous operations
How to do itâŠ
How it worksâŠ
There's more...
See also
Shutting down and closing a socket
How to do itâŠ
The client application
The server application
Closing a socket
How it worksâŠ
See also
3. Implementing Client Applications
Introduction
The classification of client applications
Synchronous versus asynchronous
The sample protocol
Implementing a synchronous TCP client
How to do itâŠ
How it worksâŠ
The SyncTCPClient class
The main() entry point function
See also
Implementing a synchronous UDP client
How to do itâŠ
How it worksâŠ
The SyncUDPClient class
The main() entry point function
See also
Implementing an asynchronous TCP client
How to do itâŠ
How it worksâŠ
Starting the application â the main() entry point function
Request completion â the handler() callback function
The AsyncTCPClient class â initializing
The AsyncTCPClient class â initiating a request
The AsyncTCPClient class â canceling the request
The AsyncTCPClient class â closing the client
There's moreâŠ
Implementing a multithreaded TCP client application
See also
4. Implementing Server Applications
Introduction
The sample protocol
Implementing a synchronous iterative TCP server
How to do itâŠ
How it worksâŠ
The Service class
The Acceptor class
The Server class
The main() entry point function
Eliminating the drawbacks
Stopping a server in reasonable amount of time
Dealing with the server's vulnerability
Analyzing the results
See also
Implementing a synchronous parallel TCP server
How to do itâŠ
How it worksâŠ
The Service class
The Acceptor class
The Server class
The main() entry point function
Eliminating the drawbacks
See also
Implementing an asynchronous TCP server
How to do itâŠ
How it worksâŠ
The Service class
The Acceptor class
The Server class
The main() entry point function
See also
5. HTTP and SSL/TLS
Introduction
Implementing the HTTP client application
How to do itâŠ
The HTTPResponse class
The HTTPRequest class
The HTTPClient class
The callback and the main() entry point function
How it worksâŠ
The HTTPClient class
The HTTPRequest class
The HTTPResponse class
Callback and the main() entry point functions
See also
Implementing the HTTP server application
Getting readyâŠ
How to do itâŠ
How it worksâŠ
See also
Adding SSL/TLS support to client applications
Getting readyâŠ
How to do itâŠ
How it worksâŠ
The SyncSSLClient class
The main() entry point function
See also
Adding SSL/TLS support to server applications
Getting readyâŠ
How to do itâŠ
How it worksâŠ
The Service class
The Acceptor class
See also
6. Other Topics
Introduction
Using composite buffers for scatter/gather operations
Getting readyâŠ
How to do itâŠ
Preparing a composite buffer for gather output operations
Preparing a composite buffer for an input operation
How it worksâŠ
See also
Using timers
How to do itâŠ
How it worksâŠ
Getting and setting socket options
Getting readyâŠ
How to do itâŠ
How it worksâŠ
Performing a stream-based I/O
How to do itâŠ
How it worksâŠ
There's moreâŠ
Implementing a server-side I/O
Setting timeout intervals
Index
Boost.Asio C++ Network Programming Cookbook
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: January 2016
Production reference: 1190116
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78398-654-5
www.packtpub.com
Author
Dmytro Radchuk
Reviewer
Victor Sigler
Commissioning Editor
Usha Iyer
Acquisition Editors
Shaon Basu
Manish Nainani
Content Development Editor
Samantha Gonsalves
Technical Editor
Madhunikita Sunil Chindarkar
Copy Editors
Trishya Hazare
Rashmi Sawant
Project Coordinator
Kinjal Bari
Proofreader
Safis Editing
Indexer
Hemangini Bari
Production Coordinator
Shantanu N. Zagade
Cover Work
Shantanu N. Zagade
Dmytro Radchuk is a software engineer from Kyiv, Ukraine. His passion for science started at a young age and led him to receive a degree in computer science from Kyiv Polytechnic University. As of today, he has deep technical knowledge and more than 8 years of experience in the field of software development for several industries and businesses. He strongly believes that the whole is greater than the sum of its parts and this is one of the reasons why the development of distributed applications has become his main specialization.
Dmytro has always supported the idea of sharing knowledge and this has resulted in Boost.Asio C++ Network Programming Cookbook, which has become his first officially published book. He believes that science will help us deal with the monotony of everyday life. When he is not exploring another facet of computer engineering, he is probably learning a new aspect of psychology, history, or the arts, which are also of great interest to him.
Victor Sigler is an iOS software engineer with experience in developing consumer and enterprise mobile applications. He loves everything that is related to Apple and is passionate about Swift and the world of programming contests, where he has spent a long time developing in C++. He enjoys writing about iOS development in his blog at http://www.vsigler.com and also enjoys helping people with their queries on Stack Overflow. He...