It is modern and simple in use C++
socket library that provides the connection between client and server
This is a
fairly low-level C++ library that includes
that are familiar concepts from other languages.
wraps a system socket handle, and maintains its lifetime. When the C++ object
goes out of scope, it closes the underlying socket handle. Socket objects are
generally moveable but not copyable. A socket
can be transferred from one scope (or thread) to another using
Currently supports: IPv4, IPv6, and Unix-Domain
Sockets on Linux, Mac, and Windows.
A conforming C++-14 compiler.
CMake v3.5 or newer.Doxygen (optional) to generate API docs.Catch2 (optional) to build and run unit tests.
- gcc v5.0 or later (or) clang v3.8
Studio 2015, or later on WIndows.
Build system used: CMake.
Namespace used: sockpp
For Linux users: Set the
standard targets to build and install this library, and then
run ldconfig to insure that the loader cache is updated:
$ git clone
$ cd sockpp
$ sudo make install
$ sudo ldconfig
- ü When a connection is accepted,
a new, streaming socket is created. That new socket can be handled directly or
moved to a thread (or thread pool) for processing.
- ü When connected, the socket is a
streaming one, which can be used to read and write, directly.
- ü The TCP client is somewhat
simpler in that a
tcp_connector object is created and connected, then can be used to
read and write data directly.
- ü UDP sockets can be used for
- ü A
socket can be moved from one
thread to another safely. This is a common pattern for a server which uses one
thread to accept incoming connections and then passes off the new socket to
another thread or thread pool for handling.
can be moved.
- ü The
socket::shutdown() method can be used to communicate the intent to close
the socket from one of these objects to the other without needing another
thread signaling mechanism.
- ü A socket object is not
thread-safe. Applications that want to have multiple threads reading from a
socket or writing to a socket should use some form of serialization, such as a
std::mutex to protect access.
- ü The default constructors for
each of the socket classes do nothing, and simply set the underlying handle to
INVALID_SOCKET. They do not create a socket object. The call to actively
connector object or open an
acceptor object will create an underlying OS socket and then
perform the requested operation.
socket cannot be copied.