I've been developing LightnerX, an open-source C++ networking library for multiplayer games, and one of the things I've spent time working on is how messages are sent to connected clients.

It sounds simple at first. You have a message, you have a connection, and you send it.

But multiplayer applications don't always need to send messages to just one client.

Sometimes you want to send something to a specific player. Sometimes to a group of players. And sometimes to everyone connected to the server.

I wanted LightnerX to handle these cases through a consistent interface.

The Target abstraction

In LightnerX, I introduced an abstraction called Target.

It represents the intended recipients of an outgoing message.

There are three delivery modes:

  • Single: Send a message to one specific connection.
  • Group: Send a message to a selected group of connections.
  • Broadcast: Send a message to all applicable connected clients.

Consider a multiplayer game where players are divided into teams.

If a player receives a private notification, you only need to send it to that player's connection.

If something happens that affects an entire team, you can target that group.

And if the server needs to announce a global event, broadcasting makes more sense.

Instead of treating each of these as an unrelated operation, LightnerX uses Target to represent the delivery destination.

Message batching

Another part of this system is message batching.

LightnerX provides an outgoing message queue, allowing messages to be prepared before they're sent.

The main operations are:

  • initMessagesBatcher(capacity) — Initialize the batcher with a specified capacity.
  • queueMessage(...) — Queue an outgoing message with its target.
  • flushAll() — Flush the queued messages.

This gives the application control over when it prepares messages and when it flushes them through the underlying networking layer.

An important distinction: batching messages does not automatically mean combining them into a single network packet.

The system is primarily about organizing outgoing messages and their destinations.

Why GameNetworkingSockets?

LightnerX uses Valve's GameNetworkingSockets as its underlying transport.

I didn't want to build an entire networking transport from scratch.

Instead, I wanted to focus on the parts of multiplayer networking that sit above the transport layer:

  • Managing connected clients.
  • Organizing message delivery.
  • Interpreting incoming messages.
  • Handling structured client-server communication.

For that last part, LightnerX implements INER, a communication model I designed around Intention, Notification, Event, and Response messages.

The transport handles the actual networking, while LightnerX provides additional structure for applications using it.

Still improving it

LightnerX is an ongoing project, and I'm continuing to work on its implementation, tests, and documentation.

My goal isn't to create a complete multiplayer game engine. It's to provide a networking library that can be integrated into different projects without forcing developers to adopt an entire framework.

I'm sharing it because I'd like to hear how other developers approach similar problems.

How do you organize outgoing messages in your multiplayer applications?

Do you usually implement separate functions for unicast, group delivery, and broadcast, or do you prefer a unified abstraction?

I'd be interested in hearing about the trade-offs you've encountered.

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