StormByte C++ Library: Network module 1.1.0
StormByte-Network is the C++26 networking module of the StormByte suite.
Loading...
Searching...
No Matches
StormByte-Network

Multiplatform C++26 CMake License: LGPL v3 CI Sponsor

StormByte-Network is the C++26 networking module of the StormByte suite.

It depends on StormByte Base 1.1.0 (or newer), StormByte Buffer 1.1.0 (or newer), and StormByte Logger 1.1.0 (or newer).

It is not a thin socket wrapper. You inherit Client or Server, define packets, and attach Buffer pipelines. POSIX and Winsock, framing, event-driven I/O and bounded packet processing stay private.

Table of Contents

  • Repository
  • Installation
  • Why StormByte-Network
  • Features
  • Dependencies
  • The rest of the suite
  • Public API
  • Examples
    • A client
    • A server
    • A packet
  • Design notes
  • Testing
  • Contributing
  • License

Repository

Installation

git clone https://github.com/StormBytePP/StormByte-Network.git
cd StormByte-Network
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
cmake --install build

Why StormByte-Network

Goal How it is achieved
Inherit, don't wrap sockets Client / Server are abstract application endpoints.
Framed messages Transport::Packet + private Frame (opcode, size, payload).
Buffer as I/O Pipelines on inbound/outbound payloads; Reader/Writer adapters.
IPv4 and IPv6 Connection::Protocol.
Cross-platform POSIX and Winsock behind Socket / Handler.

Features

  • Abstract Endpoint, Client, Server
  • Packet factory (DeserializePacketFunction)
  • Connection status, read/write results
  • Request/response (Send) and fire-and-forget (Reply)
  • Server event loop with bounded packet-handler workers
  • Per-session in-flight ordering, bounded output buffering and backpressure handling
  • Optional payload processing for opcodes ≥ Packet::PROCESS_THRESHOLD

Dependencies

Dependency Required Version Role
StormByte (base) 1.1.0 Expected, exceptions, visibility
StormByte-Buffer 1.1.0 FIFO, Pipeline, Consumer, External I/O
StormByte-Logger 1.1.0 Diagnostics

The rest of the suite

Module Role API
Base Exceptions, Expected, serialization, strings, UUID, concepts /StormByte
Buffer FIFO, SharedFIFO, Ring, Producer/Consumer and multi-stage pipelines /StormByte-Buffer
Config Human-readable text and versioned binary documents (groups, lists, raw bytes) /StormByte-Config
Crypto Hash, compress, encrypt, sign and key agreement — Crypto++ never leaves the private tree /StormByte-Crypto
Database One API over SQLite, PostgreSQL and MariaDB /StormByte-Database
Logger Stream logger with levels, headers, human-readable sizes and redaction (ThreadedLog) /StormByte-Logger
Multimedia Decode, encode and containers without raw FFmpeg types; codecs enabled only if present /StormByte-Multimedia
Network This repository /StormByte-Network
System Processes, pipes and environment variables across Linux, Windows and macOS /StormByte-System

Public API

Under StormByte::Network:

Type Role
Client Inherit; implement pipelines; call Send
Server Inherit; implement ProcessClientPacket
Transport::Packet Inherit; implement DoSerialize
Connection::Protocol IPv4 / IPv6
Connection::Status Lifecycle
Exception / ConnectionError / ConnectionClosed Errors

Sockets, frames and Winsock bootstrap are private.

Examples

A client

class AppClient : public StormByte::Network::Client {
public:
std::shared_ptr<StormByte::Logger::Log> log)
: Client(fn, log) {}
protected:
StormByte::Buffer::Pipeline InputPipeline() const noexcept override {
return {};
}
StormByte::Buffer::Pipeline OutputPipeline() const noexcept override {
return {};
}
};
Abstract application client.
Definition client.hxx:43
virtual Buffer::Pipeline InputPipeline() const noexcept=0
Pipeline applied to inbound frame payloads.
virtual Buffer::Pipeline OutputPipeline() const noexcept=0
Pipeline applied to outbound frame payloads.
std::function< PacketPointer(Transport::Packet::OpcodeType, Buffer::Consumer, std::shared_ptr< Logger::Log >)> DeserializePacketFunction
Callback that builds a Packet from opcode + payload consumer.
Definition typedefs.hxx:68

A server

class AppServer : public StormByte::Network::Server {
public:
using Server::Server;
protected:
StormByte::Buffer::Pipeline InputPipeline() const noexcept override { return {}; }
StormByte::Buffer::Pipeline OutputPipeline() const noexcept override { return {}; }
StormByte::Network::PacketPointer ProcessClientPacket(
const std::string& uuid,
StormByte::Network::PacketPointer packet) noexcept override {
(void)uuid;
return packet;
}
};
Abstract application server.
Definition server.hxx:55
std::shared_ptr< Transport::Packet > PacketPointer
Shared packet.
Definition typedefs.hxx:59

A packet

class PingPacket : public StormByte::Network::Transport::Packet {
public:
PingPacket() : Packet(1) {}
protected:
StormByte::Buffer::DataType DoSerialize() const noexcept override {
return {};
}
};
Polymorphic wire packet: opcode + payload hook.
Definition packet.hxx:38
virtual Buffer::DataType DoSerialize() const noexcept=0
Payload-only serialization (no opcode).

Design notes

  • One connection is not a thread-safe multiplex. The server keeps socket I/O in its event loop and dispatches packet handlers through a bounded internal pool.
  • Client request/response APIs remain synchronous to the caller; a slow packet handler no longer blocks socket I/O for unrelated clients.
  • A slow peer is isolated by per-session output limits; once a session exceeds its output budget, the server closes that session rather than allowing unbounded memory growth.
  • Connect on Server means bind + listen + accept loop.
  • Frame layout uses host size_t for payload length. Same architecture on both ends.
  • Pipelines run only when the opcode is at or above PROCESS_THRESHOLD.

Testing

Enable tests in CMake (ENABLE_TEST) and run CTest from the build tree.

Contributing

Issues on GitHub. No wiki, no discussions.

License

GNU Lesser General Public License v3 or later.

See https://www.gnu.org/licenses/lgpl-3.0.html.