I'm a newcomer to using C++ but have got a general Idea of its syntax and usability. I want to learn how to communicate over networks through C++ programming though but I can't seem to find any tutorials for C++ specifically. Does anyone know any good resources to learn about networking with C++ or what I should start with?
-
5I gave an extensive answer for socketprogramming in C++ [here](http://stackoverflow.com/questions/2843277/c-winsock-p2p/2920787#2920787). Hope that can help – default Oct 03 '10 at 13:11
-
It was being considered for C++20, but got deferred: https://en.wikipedia.org/wiki/C%2B%2B20 Already present in GCC under experimental/ however. – Ciro Santilli OurBigBook.com Dec 31 '20 at 10:08
7 Answers
Given your newness to C++, I would not recommend building directly on the sockets APIs unless you can find no suitable library to use. Boost.Asio will give you a huge head start and expose you to the higher-level abstractions used in network programming.
It's easy when starting out building a sockets-based system to get something that 'sort of' works and then spend weeks debugging corner cases that only happen under real-world timing and load conditions. Using boost::asio
correctly is hardly a cakewalk even if it shields developers from the complexities of raw socket handling.
If the goal is to learn how to use raw sockets (or some other transport mechanism such as RPC) correctly, then by all means roll your own using online samples and docs to understand the individual BSD or Winsock APIs - if the goal is to solve a business problem as quickly as possible with high quality code on both business and networking infrastructure side, then use a good networking library. In this case your question does indicate a wish to learn so using a library may not be the best way to achieve your stated goal.

- 53,498
- 9
- 91
- 140
-
2For some reason my group is opposed to the idea of using boost.asio, do you know why this might be? It seems like a valid way to approach this sort of thing :S – CoderDake Oct 02 '10 at 22:53
-
24The problem with your reasoning (new people -> socket APIs are too advanced) is that.. well.. with that attitude, how can you expect him to learn? Sometimes you have to force yourself to dabble in things above your comfort level. The "find a library to do everything" approach, especially in such a simple topic, contributes to the problem that there are so few people who can implement these libraries in the first place. – asveikau Oct 03 '10 at 00:16
-
3
-
3@TopGunCpp, I don't know, you should ask them to understand the reasoning. Some groups just have a builtin hostility to NIH ('Not Invented Here') code. Perhaps they want to build in-house networking/sockets expertise by building this from scratch. – Steve Townsend Oct 03 '10 at 13:07
You should check out these guides about:
And Boost.Asio Look here for a question on documentation related to Boost.Asio

- 72,253
- 8
- 102
- 198

- 126,773
- 69
- 172
- 181
I'm sure a bunch of C++ people who despise the C way of doing things will hate me for this, but the classical approach is to use the Berkeley socket APIs (so-called because they have their origins in BSD). If you're targeting Windows, the "largely-source-compatible, inspired-by-Unix" APIs are called Winsock. I'd say do a web search for socket tutorial and you will probably get some useful information. With a little care and maybe an #ifdef
or two, it's not so hard to create code which works on Linux, BSD, Mac (which provide BSD sockets) and Windows (with Winsock) using what's common between these two interfaces.
For the more C++ inclined, less C-style people, or those who don't like to code against OS APIs, I'm sure there are C++ libraries out there that provide wrappers and abstractions for these same concepts. Since Boost seems to be pretty popular, I'd say see what they have.

- 39,039
- 2
- 53
- 68
The standard library of C++ doesn't have support for this, so you either have to use the system API or some abstraction library, e.g. QT.

- 3,478
- 2
- 22
- 24
Library:
Book:
- C++ Network Programming, Volume I: Mastering Complexity with ACE and Patterns
- C++ Network Programming, Volume II: Systematic Reuse with ACE and Frameworks
(and take look at: ACE vs Boost vs POCO - Best C/C++ Network Library)

- 2,942
- 1
- 14
- 16

- 1,124
- 1
- 17
- 27
C++ is an Object Oriented language and open so you can borrow from other languages particularly C. but here are a few books that might help. http://wjyl.nuaa.edu.cn/kfyy/article/C++%20Network%20Programming%20Volume%201.pdf and perhaps http://www.cs.wustl.edu/~schmidt/PDF/ACE-tutorial.pdf among many. there others out there as well.

- 11
- 1