cpp-tcpnet
cpp-tcpnet is a robust, cross-platform, header-only C++ library for TCP client and server networking. It uses cpp-pubsub for event dispatching and provides easy-to-use, non-blocking networking capabilities.
Key Features
- Cross-Platform: Works natively on Windows (
Winsock2) and Linux/macOS (POSIX). - DNS Resolution & IPv6: Resolve hostnames dynamically on client connections. Fully supports both IPv4 and IPv6 (
AF_INET6), including dual-stack wildcard binding. - SSL/TLS Support: Secure encrypted transport using OpenSSL/LibreSSL (TLS 1.2+).
- Asynchronous & Non-Blocking: High-performance background event loop ensures the main thread is never stalled by network IO.
- Built-in Thread Pool with Session Affinity: Automatically dispatches incoming packet data to a background worker pool, guaranteeing that callbacks for any single session are executed serially (in-order), while different sessions are processed concurrently.
- Event-Driven: Uses the
cpp-pubsubbroker to publish events whenever connections connect or disconnect. - Peer Address API: Retrieve the remote peer’s IP address and port for any active session with
GetPeerAddress(session_id). - Zero-Copy Transmissions: Safely bypass memory allocations and data copying during transmission using C++17 move semantics (
std::move) or shared reference counts (std::shared_ptr<const T>). - Dynamic Connection Profiles: Package socket options and application network configurations into preset or custom
ConnectionProfileobjects and apply them dynamically on the fly per session. - Highly Configurable: Fine-tune socket options (Nagle’s algorithm, keepalives, linger, reuse port), thread pool bounds, outbound buffer limits, dynamically allocated receive buffers, custom cipher suites, TLS version bounds, idle timeouts, and automatic client reconnection with backoff.
- Performance Metrics: Monitor cumulative bytes/packets sent and received, connection counts, calculate real-time throughput using the sliding-window
ThroughputTracker, and scale raw counts using formatting helpers.
Documentation Pages
Welcome to the cpp-tcpnet documentation! Please follow the guide below to learn how to integrate and use the library:
-
Getting Started Learn how to integrate
cpp-tcpnetinto your project via CMake or direct inclusion. -
Basic Usage Learn how to start a TCP server and handle incoming connections.
-
Advanced Usage Learn how to connect a TCP client and handle asynchronous messaging.
-
Performance Metrics Learn how to monitor network statistics and track real-time throughput.
-
Architecture & Examples Understand the architecture behind the library and its multi-threaded event loop.