The essence of actual combat
Boost your grid in specific C + + network programming
John Torjo
Boost.asio C + + network programming
Copyright? Packt Publishing
About the author
As an authoritative C + + expert,John Torjo has been programming for more than 15 years, and for the past 15 years, he has spent most of his time in research, in addition to occasional C#
and Java
written programs C++
.
He also likes to write some programming related articles in C + + Users Journa L and other magazines.
In his spare time, he likes to play poker and drive fast. He has a lot of freelancing, and one of them combines his hobby of playing poker and programming, and if you want to contact him, you can email [email protected].
I want to thank my friends Alexandru Chis, Aurelian Hale, Bela Tibor Bartha, Cristian Fatu, Horia Uifaleanu, Nicolae Ghimbovschi and Ovidiu D Eac. Thank them for the feedback and suggestions they have made on this book. At the same time, I also want to thank the Packt company for my frequent miss deadline behavior of inclusion. And then the most thankful is the author of Chris Kohlhoff,boost.asio, who wrote such a great library.
Dedicate this book to my best friend, Darius.
About the Assessor
Béla Tibor Bartha
A professional software engineer who develops in a variety of technologies and languages. Although he has been working with application development for the past 4 years, he iOS
OSX
C++
has spent the passionate years of early development of individual game projects.
I want to thank John because I'm the judge of this book.
Nicolae Ghimbovschi
A C++
talented individual developer who has participated in a variety of projects for more than 5 years. He is mainly involved in a number of corporate communications engineering projects. As an avid Linux
enthusiast, he likes to test and experiment with different operating systems, scripting tools, and programming languages. In addition to programming, he also enjoys cycling, yoga and meditation.
I want to thank John for letting me judge this book.
About translators
Painting Slag program Ape Mmoaay, Bad technology, like graphic design, mouse painting, dating, sports and translation, but indeed as a procedural ape in the IT industry. Love Open source, the technology is rotten to do the work of design and translation.
Weibo: Http://weibo.com/smmoaay
About Avplayer
Http://avplayer.org China's first technology community.
Directory
Objective
Chapter One: Introduction to Boost.asio
什么是 Boost.Asio? 历史 依赖 编译 Boost.Asio 重要的宏同步 VS 异步异常 VS 错误代码Boost.Asio 中的多线程不仅仅是网络计时器io_service 类总结
Chapter II: Boost.asio Fundamentals
网络 APIBoost.Asio 命名空间IP 地址端点Sockets 同步错误代码 Socket 成员函数 其他注意事项read/write/connect自由函数 connect 函数 read/write 函数异步编程 为什么要异步? 异步 run(),run_one(),poll(),poll_one() 持续运行 run_one(),poll(),poll_one() 函数 异步工作 异步 post() VS dispatch() VS wrap()保持运行总结
Chapter Three: Echo Server/Client
TCP 回显服务端/客户端 TCP 同步客户端 TCP 同步服务端 TCP 异步客户端 TCP 同步服务端 代码UDP 回显服务端/客户端 UDP 同步回显客户端 UDP 同步回显服务端总结
The fourth chapter: client and server
同步客户端/服务端 同步客户端 同步服务端异步客户端/服务端 异步客户端 异步服务端总结
Fifth: Synchronous vs Asynchronous
同步异步混合编程客户端和服务端之间消息的互相传递客户端软件中的同步 I/O服务端软件中的同步 I/O 同步服务端中的线程客户端软件中的异步 I/O服务端软件中的异步 I/O 异步服务端中的线程异步操作代理实现总结
Sixth chapter: boost.asio-Other Features
std streams 和 std buffer I/OBoost.Asio 和 STL流streambuf 类处理 streambuf 对象的自由函数协程总结
Seventh chapter: boost.asio-Advanced
Asio VS Boost.Asio调试 处理程序跟踪信息 例子 处理程序跟踪文件SSLBoost.Asio 的 Windows特性 流处理 随机存储处理 对象处理Boost.Asio 的 POSIX 特性 本地 sockects 连接本地 sockets POSIX 文件描述符 Fork 总结
Index
Objective
Network programming is a long-standing and challenging task. Boost.asio is an excellent abstraction for network programming, ensuring that only a small amount of programming is required to achieve an elegant client/server software. In the process of implementation, it can make you feel great fun. And more useful: Boost.asio contains some non-network features, the code written in Boost.asio is compact, easy to read, and if you do what I say in the book, your code will be impeccable.
What does the book cover?
Chapter One: Boost.asio introduction will tell you what Boost.asio is? How do I compile it? There will be some examples. You will find that Boost.asio is more than just a network library. You will also be exposed to the most core classes in Boost.asio io_service
.
Chapter II: The Boost.asio Fundamentals contain what you must know: When to use Boost.asio? We'll dive into asynchronous programming--a much more tricky and fun way to do it than syncing. This chapter is also a chapter in the development of your own Web application as a reference.
Chapter Three: the Echo Server/client will show you how to implement a small client/server application; It might be the simplest client/server application you've ever written. echo application is to send a message sent back to the client and then close the Client connection service. We will implement a synchronous version first and then implement an asynchronous version so that it is very easy to see the difference between them.
Fourth: The client and server will discuss in depth how to create a simple client/server application with Boost.asio. We will discuss how to avoid defects such as memory leaks and deadlocks. All programs simply implement a simple framework that makes it easier to extend them to meet your needs.
Fifth: Synchronous VS Async will take you through what you need to consider when choosing between synchronous and asynchronous methods. The first thing is not to confuse them. In this chapter, we will find it very easy to implement, test, and debug each type of application.
the sixth chapter: other features of Boost.asio will take you to understand some of the boost.asio features. You will find that although STD streams and streambufs are a little hard to use, they show their unique advantages. Finally, it's a belated boost.asio that allows you to write asynchronous code in an easier-to-read way. (as if writing synchronous code)
The Seventh chapter: The Boost.asio includes some boost.asio advanced problem processing. Although you don't need to delve into them in your daily programming, it's good to know about them (Boost.asio advanced debugging, Ssl,windows features, POSIX features, and so on).
What do you need to prepare before reading this book?
If you want to compile Boost.asio and run the example in this book, you need a modern compiler. For example, Visual Studio 2008 and later or g++ 4.4 and later
Who is this book written for?
This book is a boon for developers who need to do network programming but do not want to delve into complex, original Web APIs. All you need is a set of APIs provided by Boost.asio. As part of the famous Boost C + + library, you only need to add a few additional #include files to convert to Boost.asio.
Before you read this book, you need to familiarize yourself with some of the boost core library's knowledge, such as boost smart pointers, boost::noncopyable, boost Functors, boost Bind, Shared_ from_this/enabled_ Shared_from_this and Boost threads (Threads and mutexes). You also need to understand the date/time of Boost. The reader also needs to know the concept of blocking and the "non-blocking" operation.
Conventions
This book uses different styles of text to distinguish different kinds of information. Examples of these styles and their explanations are given here.
The code in the text will appear this way: "A typical io_service
example is enough".
The code is as follows:
read(stream, buffer [, extra options])async_read(stream, buffer [, extra options], handler)write(stream, buffer [, extra options])async_write(stream, buffer [, extra options], handler)
Professional vocabulary and important words are shown in bold
[! Warnings or important comments in a box like this ]
[? Skill in a box like this ]
Reader Feedback
We welcome feedback from the readers. Tell us what you think about the book-which part you like and what you don't like. Readers ' feedback is very important to us and it allows us to write books that are more helpful to our readers.
You only need to send an email to [email protected] for feedback, note the title in the subject of the message.
If you have a topic that you are good at, you want to write a book or contribute to a book. Please read our author's guide on the www.packtpub.com/authors.
User support
Now that you are the owner of the Packt book, we will tell you a few things to maximize the gains you get from buying this book.
Download Sample Code
You can log in to your account at http://www.packtpub.com and then download all the sample code for the book you purchased. You can also register by visiting Http://www.packtpub.com/support, and then these sample code files will be sent directly to your mailbox.
Error correcting
Although we have done our best to ensure the accuracy of the contents of the book, mistakes are unavoidable. If you find errors in our books-maybe text, maybe code-we would appreciate it if you could report them to us. In this way, you can not only help other readers, but also help us to improve the next version of the book. If you find any place you need to correct, visit Http://www.packtpub.com/submit-errata, select your book, click errata Submission Form link, Then enter the detailed error correction information to report the errors to us. Once determined, your submission will pass, and the error will be uploaded to our site or added to the error correction list in the error correction area of the book. All detected errors can be accessed by Http://www.packtpub.com/support and then viewed by selecting the title.
Answering
If you have any questions about this book, you can contact us by [email protected] . We will do our best to answer
Preface (Csdn also has markdown, good Kai Sen)