user9232663
user9232663

Reputation:

C++ Socket Programming

I'm wondering if there's any simple and clean way to create, write to, and receive from network sockets in C++. I know in C you can use sys/sockets among other low-level libraries, but is there anything superior for C++? We're on C++-17 and yet I still can't find much about socket programming. On Python it's easy, but C++ makes it intimidating for me.

Upvotes: 7

Views: 6158

Answers (2)

Jay
Jay

Reputation: 2888

2022

Still nothing in the standard library. However, there is a clean thin solution in the form of kissnet.

It's a thin wrapper (~1500 lines) around respective socket headers in Linux / Windows.

Secure sockets via OpenSSL.

C++ 17 compiler is required, as they're using std::byte and other perks.

Why isn't something like this in the standard library? Beats me.

Upvotes: 6

Miles Budnek
Miles Budnek

Reputation: 30704

The C++ standard library does not currently have any socket or network functionality. The standards committee does have a networking subgroup, who are working on a Networking TS (current draft), but that didn't make it into C++17.

For the time being, there's Boost.Asio, which the Networking TS is largely based upon. That provides a cross-platform networking interface. Of course, you can also directly use your OS's networking APIs, such as POSIX sockets or WinSock.

Upvotes: 6

Related Questions