简体   繁体   中英

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.

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.

2020

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

It's a thin wrapper (~1700 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM