Portable lightweight C++ sockets wrapper

前端 未结 9 1974
隐瞒了意图╮
隐瞒了意图╮ 2020-12-31 01:58

I really thought this would be easier to find...

I need a portable c++ sockets wrapper. I\'m planning to use it for a windows server application and a client that w

相关标签:
9条回答
  • 2020-12-31 02:15

    Perhaps you can have a look at http://www.pt-framework.org/

    0 讨论(0)
  • Just learn to use the socket API directly. You can then easily wrap it yourself. It's not that hard, and you can get started with Beej's excellent guide. As Beej says:

    The sockets API, though started by the Berkeley folk, has been ported to many many platforms, including Unix, Linux, and even Windows.

    In his guide he details the very small addition you need to do to get the same API in Windows and *nix systems.

    Once you've learned, wrap it yourself if you're so inclined. Then you can control exactly how "lightweight" you want it.

    0 讨论(0)
  • 2020-12-31 02:17

    Old question, but for C++, BSD style synchronous sockets this is about as minimal baggage wrapper as you can find http://code.google.com/p/ting/source/browse/trunk/src/ting/net/

    It does come with exceptions. You could make a bit more lightweight one as a header-only template library, and maybe make exceptions optional, but that would change the API a bit

    POCO network classes are quite similar, but do require more dependencies from other parts of the Poco lib

    0 讨论(0)
  • 2020-12-31 02:20

    I know this is old, but there is a very nice and simple implementation in below location which I'm using for personal use. Had implemented my own wrapper a while back but lost the code and found this one online which is much better than mine:

    http://cs.ecs.baylor.edu/~donahoo/practical/CSockets/practical/

    0 讨论(0)
  • 2020-12-31 02:23

    Take a look at ENet http://enet.bespin.org/ it is very lightweight and portable and works on top of UDP, with optional support for reliable packets. It is easy to use, the API is low-level and with little performance overhead. You have a high degree of control over the memory management, which could be good if networking is a bottleneck for you and the malloc/new implementation you use performs badly under multithreading.

    It would not be that hard to implement your high level thread “optimally”, since there is optional support for blocking receive and the library is a “library” and not a framework therefore you are the decision maker instead of the library.

    0 讨论(0)
  • 2020-12-31 02:25

    I'd suggest Boost.Asio. Despite it's name, you are not forced to use asynchronous I/O. You could use synchronous I/O and threads, as your question implies.

    Boost.Asio is a cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach.

    0 讨论(0)
提交回复
热议问题