Start learning C++ socket programming

Jan 3, 2019 at 10:52pm
Hello,

I'm a C++ programmer and my experience is rather fine in this case. For some Qt app written on Windows, I need socket programming. This will be the first time I go for learning such a great thing.

I think it's better to start firstly by socket programming and when experienced, network programming then. Agree? I need a good tutorial to teach me C++ socket programming in pdf. Yeah, there might be many good ones on the web, but I believe you more, to introduce me the one which is very good and proper for me. As well as, I needn't a complete reference, just a good tut for beginning.

What do you suggest, please?

Jan 4, 2019 at 12:22am
it's better to start firstly by socket programming and when experienced, network programming then. Agree?
What's the difference between the two?

Probably best to start here, since you already know some Qt:
http://doc.qt.io/qt-5/qtcpsocket.html
http://doc.qt.io/qt-5/qabstractsocket.html
Jan 4, 2019 at 2:37pm
I don't know. Probably network programming is a little wider than socket programming.

If possible, suggest something aprt from Qt Docs, please. I find them hard to learn something new from.

One thing, can we use C++ for socket programming?
If yes, and it's good to learn, please give me some resource to start studying it from zero.
After learning that tut, I will go to deal with Qt Docs, because I'll have gathered some info in this regard.
Jan 4, 2019 at 2:59pm
Jan 4, 2019 at 3:01pm
I don't know. Probably network programming is a little wider than socket programming.
Non-socket network programming is highly technical with fairly niche applications. Are you going to develop firewalls, software routers, packet sniffers, or OS drivers? If not then there's not much point.

One thing, can we use C++ for socket programming?
Of course. How could Qt, a C++ library, provide a sockets interface otherwise?

Maybe take a look at the MS documentation for Winsock? The MSDN is usually well-written.
https://docs.microsoft.com/en-us/windows/desktop/winsock/using-winsock
Jan 4, 2019 at 3:50pm
See: https://beej.us/guide/bgnet/

Do you mean this: https://beej.us/guide/bgnet/html/single/bgnet.html

But it's apparently in C. I don't know C. I only know C++.

Maybe take a look at the MS documentation for Winsock? The MSDN is usually well-written.
https://docs.microsoft.com/en-us/windows/desktop/winsock/using-winsock

Thank you. I think it is written to be used by C++. I hope it's good.
Jan 4, 2019 at 4:30pm
Winsocks is a C library, as well.

But it's apparently in C. I don't know C. I only know C++.
Interfacing with C code is a basic skill for any C++ programmer. If you don't know how to do it, take this chance to learn.
Jan 4, 2019 at 4:38pm
The socket API is a C API.

There are a multitude of wrappers, take your pick.
https://stackoverflow.com/questions/118945/best-c-c-network-library

But you should at least read some of Beej's guide to get the overall feel of socket()/connect()/send()/recv()/close() though.

Class wrappers will hide more (or less) from you, but the underlying fundamentals won't go away just because you have a class and a few methods to play with.



Jan 4, 2019 at 6:06pm
It sounds as though it's impossible to deal with socket programming with C++ and without C.
Jan 4, 2019 at 6:24pm
"C" API's are everywhere, so on some level it's something you're going to have to get used to.

Besides, you can call send() from C++ just as easily as you can from C.

Sure, at some point you have to step outside your comfort zone and use some raw pointers.

But like I said, you can easily encapsulate all that in a class of your own (or use someone else's).

99% of the code will be the nice comfortable C++ you know, and a very small bit of interfacing to a C API, all hidden within a class.

Jan 4, 2019 at 6:51pm
closed account (E0p9LyTq)
It sounds as though it's impossible to deal with socket programming with C++ and without C.

Boost C++ libraries.

Specifically Boost.Asio might be what you are looking for if you don't want to spend time crawling around in the bowels of C doing your own Sockets plumbing.
https://www.boost.org/doc/libs/1_69_0/doc/html/boost_asio.html
Jan 4, 2019 at 9:40pm
Thank all of you very much for your help.
My plan is as follows. Please, interfere it if it's needed:

I firstly go for the Beej's webpage.
Then boost's one.
After these two, I suppose MSDN's would be good.
Topic archived. No new replies allowed.