Book Image

Boost.Asio C++ Network Programming Cookbook

By : Dmytro Radchuk
Book Image

Boost.Asio C++ Network Programming Cookbook

By: Dmytro Radchuk

Overview of this book

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.
Table of Contents (13 chapters)
Boost.Asio C++ Network Programming Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Implementing a synchronous TCP client


A synchronous TCP client is a part of a distributed application that complies with the following statements:

  • Acts as a client in the client-server communication model

  • Communicates with the server application using a TCP protocol

  • Uses I/O and control operations (at least those I/O operations that are related to communication with a server) that block the thread of execution until the corresponding operation completes, or an error occurs

A typical synchronous TCP client works according to the following algorithm:

  1. Obtain the IP-address and the protocol port number of the server application.

  2. Allocate an active socket.

  3. Establish a connection with the server application.

  4. Exchange messages with the server.

  5. Shut down the connection.

  6. Deallocate the socket.

This recipe demonstrates how to implement a synchronous TCP client application with Boost.Asio.

How to do it…

The following code sample demonstrates a possible implementation of a synchronous TCP client application with...