C++ multipurpose networking library for linux
  • C++ 94.6%
  • JavaScript 5.4%
Find a file
2026-05-06 04:06:17 +02:00
implementations added QUIC 2026-05-06 04:06:17 +02:00
interfaces added QUIC 2026-05-06 04:06:17 +02:00
tests added QUIC 2026-05-06 04:06:17 +02:00
.gitignore initial commit 2025-11-02 15:00:53 +01:00
LICENSE initial commit 2025-11-02 15:00:53 +01:00
project.cpp added QUIC 2026-05-06 04:06:17 +02:00
README.md added QUIC 2026-05-06 04:06:17 +02:00

Crafter.Network

A cross-platform C++ networking library providing TCP and HTTP client/server functionality with modern C++ features.

Overview

Crafter.Network is a comprehensive networking library designed for modern C++ applications. It provides TCP, HTTP, and QUIC networking capabilities with support for synchronous and asynchronous operations, making it suitable for a wide range of networking tasks including real-time multiplayer games.

Features

  • TCP Networking: Client and server implementations for TCP connections
  • HTTP Support: Full HTTP client and server implementations with routing capabilities
  • QUIC Networking: Encrypted, multi-stream transport via msquic — reliable streams for control plane, unreliable datagrams for low-latency state sync
  • Asynchronous Operations: Thread pool-based async operations for improved performance
  • Cross-Platform: Built for Unix-like systems with socket-based networking
  • Modern C++: Uses C++ modules, STL containers, and modern C++ features

Architecture

The library follows a modular design using C++20 modules:

Core Modules

  • Crafter.Network: Main module that exports all components
  • Crafter.Network:ClientTCP: TCP client implementation
  • Crafter.Network:ListenerTCP: TCP server implementation
  • Crafter.Network:ClientHTTP: HTTP client implementation
  • Crafter.Network:ListenerHTTP: HTTP server implementation
  • Crafter.Network:HTTP: HTTP protocol utilities and data structures
  • Crafter.Network:ClientQUIC: QUIC connection (client + accepted-server side) with reliable streams and unreliable datagrams
  • Crafter.Network:ListenerQUIC: QUIC listener accepting incoming connections

Components

TCP Components

ClientTCP

// Create a TCP client
Crafter::ClientTCP client("localhost", 8080);
client.Send("Hello World", 11);

// Receive data
std::vector<char> data = client.RecieveSync();

ListenerTCP

// Create a TCP listener
auto callback = [](Crafter::ClientTCP* client) {
    // Handle new connection
};
Crafter::ListenerTCP listener(8080, callback);
listener.ListenSyncSync(); // Synchronous listening

HTTP Components

ClientHTTP

// Create an HTTP client
Crafter::ClientHTTP client("httpbin.org", 80);

// Send HTTP request
std::string request = Crafter::CreateRequestHTTP("GET", "/get", "httpbin.org");
Crafter::HTTPResponse response = client.Send(request);

ListenerHTTP

// Create an HTTP listener with routes
std::unordered_map<std::string, std::function<std::string(const Crafter::HTTPRequest&)>> routes;
routes["/hello"] = [](const Crafter::HTTPRequest& req) {
    return Crafter::CreateResponseHTTP("200 OK", "Hello World!");
};

Crafter::ListenerHTTP listener(8080, routes);
listener.Listen();

Build Configuration

The project uses a configuration system with multiple build targets:

  • base: Core interfaces only
  • lib: Static library build with dependencies
  • lib-debug: Debug static library build
  • lib-shared: Shared library build with dependencies

Testing

The library includes comprehensive tests covering:

  • Compilation verification
  • HTTP receive functionality
  • HTTP send functionality
  • HTTP send/receive operations
  • Keep-alive HTTP operations
  • Large HTTP data transfers

Dependencies

  • Crafter.Thread: Thread pool management for asynchronous operations
  • msquic — fetched and built automatically as a Crafter ExternalDependency (no system install required). The build clones microsoft/msquic recursively into the per-project external cache, configures it via CMake (QUIC_TLS_LIB=quictls, tests/tools/perf disabled), and links the produced libmsquic into the QUIC modules.
    • On Linux msquic links against libnuma (provided by the numactl package on most distros).

Usage Example

#include <Crafter.Network>
#include <iostream>

int main() {
    // Simple HTTP client example
    Crafter::ClientHTTP client("httpbin.org", 80);
    
    auto request = Crafter::CreateRequestHTTP("GET", "/get", "httpbin.org");
    auto response = client.Send(request);
    
    std::cout << "Status: " << response.status << std::endl;
    std::cout << "Body: " << response.body << std::endl;
    
    return 0;
}

License

This library is licensed under the GNU Lesser General Public License version 3.0. See LICENSE for more information.

Copyright (C) 2026 Catcrafts® Catcrafts.net