Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Boost.Asio C++ Network Programming Cookbook

You're reading from   Boost.Asio C++ Network Programming Cookbook Over 25 hands-on recipes to create robust and highly-efficient cross-platform distributed applications with the Boost.Asio library

Arrow left icon
Product type Paperback
Published in Jan 2016
Publisher
ISBN-13 9781783986545
Length 248 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Author (1):
Arrow left icon
Dmytro Radchuk Dmytro Radchuk
Author Profile Icon Dmytro Radchuk
Dmytro Radchuk
Arrow right icon
View More author details
Toc

Writing to a TCP socket synchronously

Writing to a TCP socket is an output operation that is used to send data to the remote application connected to this socket. Synchronous writing is the simplest way to send the data using a socket provided by Boost.Asio. The methods and functions that perform synchronous writing to the socket block the thread of execution and do not return until the data (at least some amount of data) is written to the socket or an error occurs.

In this recipe, we will see how to write data to a TCP socket synchronously.

How to do it…

The most basic way to write to the socket provided by the Boost.Asio library is to use the write_some() method of the asio::ip::tcp::socket class. Here is the declaration of one of the method's overloads:

template<
typename ConstBufferSequence>
std::size_t write_some(
const ConstBufferSequence & buffers);

This method accepts an object that represents a composite buffer as an argument, and as its name suggests, writes some...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image