cpp_weekly icon indicating copy to clipboard operation
cpp_weekly copied to clipboard

We didn't get networking in C++20 (or C++23)! Now what?

Open lefticus opened this issue 2 years ago • 17 comments

cpprestsdk other networking libraries conan, vcpkg

lefticus avatar Jun 23 '22 00:06 lefticus

I kinda hoped I would get networking in the STL since my web framework would totally benefit from it, but I did too think that asio was way too complicated and too different than the rest of the STL.

I think at this point someone needs to think about starting a new networking library from scratch with the mindset that it's going to be in the STL; not it :)

Anyone designing such thing must probably consider that someday other transport layer protocols like QUIC might find their way into STL as well.

And also I don't think anything higher than the transport layer of OSI should be considered (not that it's been ever haha) just yet.

the-moisrex avatar Aug 29 '22 02:08 the-moisrex

POCO - https://github.com/pocoproject/poco

gelldur avatar Aug 29 '22 05:08 gelldur

boost.asio here and I don't see that changing any time soon, even if networking TS was standardized as it did not provide all the features of ASIO such as serial port access, Unix sockets etc, only IP, which is woefully insufficient

jcelerier avatar Aug 29 '22 07:08 jcelerier

I use asio, but I’d like something a bit simpler…

peppemaser avatar Aug 29 '22 10:08 peppemaser

I have used Qt for TCP and HTTP(S), and I also have used a simple in-house cross-platform wrapper library for sockets, URL handling and HTTP (without SSL). IMO, any network support layer should be able to handle TCP, UDP, HTTPS with sufficient amount of customization for HTTP. For example, I have encountered a problem with SSL on some Windows machines that I couldn't get to the bottom of, but it could be a problem root CA / chain of trust. It was essential to be able to gracefully ignore SSL errors and establish a technically insecure connection over HTTPS. I also did some things for which access to and modification of HTTP headers was needed.

VioletGiraffe avatar Aug 29 '22 12:08 VioletGiraffe

POCO - https://github.com/pocoproject/poco

That is very cool

wmerfalen avatar Aug 29 '22 16:08 wmerfalen

I have used Qt for TCP and HTTP(S), and I also have used a simple in-house cross-platform wrapper library for sockets, URL handling and HTTP (without SSL).

Exactly the same here.

warped-rudi avatar Aug 29 '22 16:08 warped-rudi

libtorrent

bdekoz avatar Aug 29 '22 18:08 bdekoz

Uvw is great https://github.com/skypjack/uvw

Elercia avatar Aug 29 '22 20:08 Elercia

Uvw is great https://github.com/skypjack/uvw

That's interesting! What makes it better than industry-standard libraries like POCO or libcurl? Or boost::asio (I won't pretend I understand what asio is for, but seems to have similarities with libuv).

VioletGiraffe avatar Aug 29 '22 21:08 VioletGiraffe

If I ever need to interface to a binary through the web, I usually just use a reverse proxy with nginx and listen locally in my application. Handles 99% of the annoyances that goes with having a server up and running... including the complexities of SSL.

wmerfalen avatar Aug 29 '22 23:08 wmerfalen

Primary Note: We have package managers today! I evaluated Hunter, Conan and vcpkg for availability of each of these libraries.

From Twitter: https://twitter.com/lefticus/status/1564017510290075650

Defacto Standard:

  • ASIO https://think-async.com/Asio/ - which is what the networking TS is based on. Can be used with or without boost conan, hunter, vcpkg

Larger utility libraries:

  • Qt https://www.qt.io/ - has all the things. Just use it if you already use Qt vcpkg, conan
  • wxWidgets - https://wxwidgets.org - Crossplatform GUI library with Networking vcpkg
  • Poco - https://pocoproject.org/ more than just networking hunter, vcpkg, poco

More "low level" networking specific libraries:

  • ACE - http://www.dre.vanderbilt.edu/~schmidt/ACE.html vcpkg (well respected, not on Github AFAICT)
  • uvw - https://github.com/skypjack/uvw - wrapper around the popular libuv vcpkg conan (1.5k ⭐)
  • Sockpp - https://github.com/fpagliughi/sockpp vcpkg (483 ⭐)
  • Trantor - https://github.com/an-tao/trantor TCP specific vcpkg conan (239 ⭐)

libcurl wrappers

  • cpr - https://github.com/libcpr/cpr hunter vcpkg conan (4.9k ⭐)
  • curlpp - https://github.com/jpbarrette/curlpp vcpkg (1.3k ⭐)
  • curlcpp - https://github.com/JosephP91/curlcpp (542 ⭐)

Message Passing Like Framework Things with Multi language Support

ZeroMQ

  • https://zeromq.org/get-started/ (C++ and ASIO style bindings available) vcpkg conan

gRPC

  • https://grpc.io/ hunter vcpkg conan (35.4k ⭐)
  • https://github.com/Tradias/asio-grpc conan, vcpkg (142 ⭐)

Websocket/HTTP specific

  • https://github.com/zaphoyd/websocketpp hunter vcpkg conan (5.8k ⭐)
  • boost beast - https://www.boost.org/doc/libs/1_73_0/libs/beast/doc/html/beast/introduction.html hunter vcpkg conan

REST

  • https://github.com/Microsoft/cpprestsdk (deprecated) vcpkg conan (7k ⭐)
  • https://github.com/pistacheio/pistache vcpkg conan (2.7k ⭐)
  • https://github.com/mrtazz/restclient-cpp vcpkg (1.4k ⭐)
  • https://github.com/Stiffstream/restinio vcpkg conan (879 ⭐)
  • https://github.com/jgaa/restc-cpp vcpkg (488 ⭐)

lefticus avatar Aug 30 '22 15:08 lefticus

Thousands of us will keep on using MPI for another decade at least.

The networking TS was a huge disappointment for me and I hope C++ takes a very different strategy next time.

jeffhammond avatar Sep 01 '22 18:09 jeffhammond

@jeffhammond: I think you completely missed the point, MPI is its own thing and is absolutely out of scope for this discussion of general-purpose networking. Of course people will keep using MPI.

VioletGiraffe avatar Sep 01 '22 18:09 VioletGiraffe

https://github.com/5cript/roar My own :P for http(s) and websocket based on boost::beast and curl. Otherwise asio, beast, libcurl

5cript avatar Sep 01 '22 18:09 5cript

@jeffhammond: I think you completely missed the point, MPI is its own thing and is absolutely out of scope for this discussion of general-purpose networking. Of course people will keep using MPI.

MPI is far more general - and sockets far less general - than you seem willing to admit. In any case, I don't want C++ to pull in MPI, just consider more than sockets.

Look at libfabric or UCX as examples of alternatives to sockets that are capable of expressing high performance networking patterns across a range of technology.

jeffhammond avatar Sep 01 '22 18:09 jeffhammond

@jeffhammond: interesting pointers, thank you! I know MPI but never heard of these two libraries.

On generality: a Turing machine is much more general than an ARM or x86 CPU, or than the C++ abstract machine, but it doesn't mean we should all be programming for the Turing machine.

VioletGiraffe avatar Sep 01 '22 19:09 VioletGiraffe

Coming in Episode 345

lefticus avatar Sep 30 '22 21:09 lefticus

I'll plug mine. :-)

https://github.com/omnifarious/StrMod

It's kind of odd, it's kind of a co-routine thing without co-routines. The co-routine state is kept in StreamModule objects. It has ropes for managing the data coming in and going out. I wrote it a very long time ago, but I do keep it somewhat up-to-date. I've written a couple of commercial things with it.

I recently modified it to build as a CMake package. I don't know if that means it'll work with one of the C++ package managers or not. When module support is more baked, I'll probably make it use modules, though I don't make heavy use of templates and so that will probably not speed up compilation much.

Omnifarious avatar Oct 10 '22 20:10 Omnifarious

Would it be worth mentioning something like epoll here?

wmerfalen avatar Nov 11 '22 03:11 wmerfalen

Would it be worth mentioning something like epoll here?

May as well post a link to it!

lefticus avatar Nov 11 '22 21:11 lefticus

epoll is just one of the low level ways on linux to wait for IO events. https://man7.org/linux/man-pages/man7/epoll.7.html There is also the new io_uring, which is potentially better than epoll and can also be enabled as an implementation in boost asio using BOOST_ASIO_HAS_IO_URING

5cript avatar Nov 12 '22 18:11 5cript

It is also worth pointing out that aedis(redis client), restinio, crowCpp are based on asio. For Qt restAPI there is also cutelyst.

kassane avatar Dec 29 '22 12:12 kassane

I've done detailed presentations on POCO, restbed, pistache, Cap'nProto and ZeroMQ for Utah C++ Programmers on our Network Programming playlist.

LegalizeAdulthood avatar Mar 07 '23 21:03 LegalizeAdulthood