DEV Community

Pietro
Pietro

Posted on

LightnerX: An Open-Source C++17 Networking Library for Multiplayer Games

I've been working on a multiplayer game in C++, and one of the things I needed was a networking layer that I could integrate into the game's architecture without giving up control over how everything runs.

That eventually became LightnerX, an open-source C++17 networking library built on top of Valve's GameNetworkingSockets.

The project started as part of my game, but I decided to turn it into a standalone library that other developers could use.

What is LightnerX?

LightnerX provides components for building client-server applications, with a particular focus on multiplayer games.

It uses GameNetworkingSockets for network transport and implements INER, a semantic communication protocol I designed to organize how clients and servers exchange messages.

The library currently provides:

  • Client and server networking using GameNetworkingSockets.
  • ConnectionManager for managing connections and internal client identifiers.
  • MessageInterpreter for parsing and interpreting INER messages.
  • Message batching for queuing outgoing messages before sending them.
  • Target for sending messages to individual connections, groups, or broadcasts, including broadcasts with exceptions.
  • Callbacks for handling connections, disconnections, received messages, and interpreted messages.
  • CMake integration through the "LightnerX" library target.

It's a library, not a framework. Your application decides when to initialize components, how frequently to call "update()", which threads to use, and how to organize its execution loop.

The INER protocol

One of the main parts of the project is INER, which stands for Intention, Notification, Event, and Response.

It defines four message types:

Message| Direction| Purpose
Intention| Client → Server| Request an action
Notification| Client → Server| Send information
Event| Server → Client| Communicate an occurrence
Response| Server → Client| Return the result of an intention

For example, in a multiplayer game, a client could send an Intention requesting to use an item.

The server evaluates the request and sends a Response indicating the result.

If something happens in the game world, the server can communicate it through an Event.

INER itself doesn't define sockets, threads, or network transport. Those responsibilities belong to the networking implementation.

Message routing and batching

LightnerX includes a "Target" abstraction for selecting the destination of outgoing messages.

You can send a message to:

  • A single connection.
  • A specific group of connections.
  • Every registered connection.
  • Every registered connection except selected ones.

Outgoing messages can also be queued and processed through the batching system.

This allows the application to prepare messages and decide when to flush the outgoing queue.

Testing and validation

I've also been working on making sure the library behaves consistently across different configurations.

The current validation suite contains 15 standard tests, while the extended configuration runs 22 tests.

The recorded validation includes:

  • GCC and Clang builds.
  • Debug and Release configurations.
  • AddressSanitizer, UndefinedBehaviorSanitizer, and leak detection.
  • Message serialization and parsing tests.
  • Connection management and lifecycle tests.
  • Documentation compilation checks.
  • Cross-version UDP interoperability tests between the original C++26 implementation and the C++17 version.

One of the differential test fixtures includes 13,275 parsing invocations and 1,897 delivered messages, allowing the migrated implementation to be compared against recorded behavior from the original version.

The documented validation runs completed without skipped tests.

Of course, passing tests doesn't mean the library is bug-free, but having this coverage makes it easier to change the implementation without accidentally breaking existing behavior.

C++17 and integration

LightnerX originally used C++26 modules, but I eventually migrated it to C++17 to make integration easier for projects using older language standards.

The current version uses traditional headers under "include/lightnerx/", CMake 3.22 or newer, and C++17-compatible alternatives for features such as "std::span" and "std::expected".

It's built as a CMake library target that applications can link against.

What's next?

LightnerX is still a relatively young project, and I'm continuing to improve its implementation, documentation, and developer experience.

My original motivation was simply to build the networking infrastructure for my own game. Turning it into an independent open-source project has been an interesting experience.

If you're working on a multiplayer game or another C++ client-server application, I'd be interested in hearing what you think about the architecture.

GitHub: https://github.com/pietroth/LightnerX

Documentation: https://pietroth.github.io/LightnerX-docs/

Top comments (0)