C++ federates
MicroRTI has no C++ client of its own. C++ federates use the C++ half of the open-source
Pitch FedProClient (Apache License 2.0), which
implements the standard HLA 4 C++ API, headers RTI/... and namespace rti1516_2025, on top of the
Federate Protocol of IEEE 1516.1-2025. This page builds it from source, compiles a small federate with
CMake and runs it against a local microrti.
The C++ client of FedProClient v2.1.1 implements plain TCP only. Asking it for
tls,websocketorwebsocketsecureends inConnectionFailed: Failed to start FedPro session: Unimplemented transport type ...before anything is sent. Give the RTI a TCP listener for C++ federates, on a network you trust.
What has been tested
The repository’s C++ interoperability harness
runs scripted scenarios with v2.1.1 against microrti over TCP: federation management, objects and
interactions, time management with both standard time representations, synchronization points,
ownership and part of the Management Object Model, with both callback models and two federates at most.
It does not prove conformance. It ran by hand on macOS (arm64, Apple clang 21, CMake 4.5.1), and a
GitHub workflow of the repository builds it with GCC and runs it every week on Ubuntu 24.04. Windows has
not been tried. The federate on this page was built and run on macOS.
What you need
- Git, curl and tar.
- CMake 3.19 or later, with
make. - A C++14 compiler. On macOS, the command line tools of Xcode and
brew install cmakeare enough. - A
micrortiserver: see Install and run the RTI.
Work in an empty directory: it will hold the client, protobuf and your federate side by side.
Build protobuf 3.21
The client’s generated protobuf sources were made for protobuf 3.21 and refuse other runtime versions. Its CMake file looks for 3.21.x and, when it finds none, builds nothing without failing. So build protobuf 3.21.12 once, as a static library in a directory of its own:
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protobuf-cpp-3.21.12.tar.gz
tar xzf protobuf-cpp-3.21.12.tar.gz
cmake -S protobuf-3.21.12 -B protobuf-build -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_PROTOC_BINARIES=OFF -Dprotobuf_WITH_ZLIB=OFF \
-DCMAKE_INSTALL_PREFIX="$PWD/protobuf-install"
cmake --build protobuf-build --parallel
cmake --install protobuf-buildThe SHA-256 of the archive is 4eab9b524aa5913c6fffb20b2a8abf5ef7f95a80bc0701f3a6dbb4c607f73460.
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 is there for CMake 4, which refuses the minimum version that
protobuf 3.21 declares.
Get FedProClient
git clone --depth 1 --branch v2.1.1 https://github.com/Pitch-Technologies/FedProClient.gitThe C++ library is in FedProClient/cpp. Its own build (see cpp/README.md there) uses CMake presets
that want Ninja and, on macOS, build for two processor architectures at once, which needs a protobuf
built the same way. The shorter route below builds the library inside your own CMake project, from the
library’s own source list. It is the route the repository’s harness takes.
A federate and its CMake file
The federate joins the chat room of MicroRTI’s chat example: federation execution Chat, FOM module
Chat.xml, interaction class Communication with two HLAunicodeString parameters, Sender and
Message. It creates the federation execution unless somebody already has, joins, publishes and
subscribes Communication, says hello once and prints every line it hears for a number of seconds.
Then it resigns, destroys the federation execution if nobody else is in it, and disconnects.
mkdir hello-cpp && cd hello-cpp
curl -O https://raw.githubusercontent.com/microrti/microrti/main/crates/microrti-examples/fom/Chat.xmlCMakeLists.txt:
cmake_minimum_required(VERSION 3.19)
project(hello_federate LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(FEDPRO_CPP "" CACHE PATH "The cpp directory of a FedProClient checkout")
find_package(Protobuf 3.21.0...<3.22.0 CONFIG REQUIRED)
find_package(Threads REQUIRED)
# What the library's source list expects from the top-level CMakeLists.txt of FedProClient.
set(HLA_1516_2010_FEDPRO_INCLUDE "${FEDPRO_CPP}/api/HLA_1516-2010")
set(HLA_1516_2025_FEDPRO_INCLUDE "${FEDPRO_CPP}/api/HLA_1516-2025")
set(FEDPRO_CXX_FLAGS_EVOLVED -Wno-deprecated-declarations)
set(FEDPRO_CXX_FLAGS_HLA4 "")
add_subdirectory("${FEDPRO_CPP}/src" fedpro EXCLUDE_FROM_ALL)
add_executable(hello hello.cpp)
target_link_libraries(hello PRIVATE fedpro_librti1516_4 Threads::Threads)fedpro_librti1516_4 is the HLA 4 library target of FedProClient; linking with it also brings the
standard headers. Built this way it is a static library, so hello runs without any shared library
next to it.
hello.cpp:
// Joins the chat room of MicroRTI's examples, says hello and prints what it hears for a while.
#include <RTI/NullFederateAmbassador.h>
#include <RTI/RTIambassador.h>
#include <RTI/RTIambassadorFactory.h>
#include <RTI/RtiConfiguration.h>
#include <RTI/encoding/BasicDataElements.h>
#include <chrono>
#include <cstring>
#include <iostream>
#include <string>
using namespace rti1516_2025;
class Hello : public NullFederateAmbassador
{
public:
ParameterHandle sender;
ParameterHandle message;
void receiveInteraction(InteractionClassHandle const &, ParameterHandleValueMap const & values,
VariableLengthData const &, TransportationTypeHandle const &, FederateHandle const &,
RegionHandleSet const *) override
{
std::wcout << L"<" << text(values, sender) << L"> " << text(values, message) << std::endl;
}
private:
static std::wstring text(ParameterHandleValueMap const & values, ParameterHandle const & parameter)
{
auto found = values.find(parameter);
if (found == values.end()) {
return L"?";
}
HLAunicodeString string;
string.decode(found->second);
return string.get();
}
};
int main(int argc, char * argv[])
{
std::string address = argc > 1 ? argv[1] : "localhost:15164";
std::wstring name = argc > 2 ? std::wstring(argv[2], argv[2] + std::strlen(argv[2])) : L"cpp";
double seconds = argc > 3 ? std::stod(argv[3]) : 10;
try {
Hello federate;
std::unique_ptr<RTIambassador> rti = RTIambassadorFactory().createRTIambassador();
rti->connect(federate, HLA_EVOKED,
RtiConfiguration::createConfiguration().withRtiAddress(std::wstring(address.begin(), address.end())));
try {
rti->createFederationExecution(L"Chat", L"Chat.xml");
} catch (FederationExecutionAlreadyExists const &) {
// somebody else opened the room first
}
rti->joinFederationExecution(name, L"hello", L"Chat");
std::wcout << L"joined Chat as " << name << std::endl;
InteractionClassHandle communication = rti->getInteractionClassHandle(L"Communication");
federate.sender = rti->getParameterHandle(communication, L"Sender");
federate.message = rti->getParameterHandle(communication, L"Message");
rti->publishInteractionClass(communication);
rti->subscribeInteractionClass(communication);
ParameterHandleValueMap hello;
hello[federate.sender] = HLAunicodeString(name).encode();
hello[federate.message] = HLAunicodeString(L"hello from C++").encode();
rti->sendInteraction(communication, hello, VariableLengthData());
auto end = std::chrono::steady_clock::now() + std::chrono::duration<double>(seconds);
while (std::chrono::steady_clock::now() < end) {
rti->evokeMultipleCallbacks(0.1, 0.5); // HLA_EVOKED: callbacks run only in here
}
rti->resignFederationExecution(NO_ACTION);
try {
rti->destroyFederationExecution(L"Chat");
std::wcout << L"left; the room is closed" << std::endl;
} catch (FederatesCurrentlyJoined const &) {
std::wcout << L"left; others are still in the room" << std::endl;
}
rti->disconnect();
} catch (Exception const & e) {
std::wcerr << e.name() << L": " << e.what() << std::endl;
return 1;
}
return 0;
}Strings of the C++ API are std::wstring. A few points that are specific to this client:
- The RTI address is
host:port, without thetcp://prefix that MicroRTI’s own tools use. createFederationExecutiongets the path of the FOM module. The client reads the file and sends its content, so the file only has to exist where the federate runs. If the client cannot open the file, it sends the name to the RTI as a URL, andmicrortirefuses it withCouldNotOpenFOM(see When it does not connect).- With
HLA_EVOKEDthe client delivers callbacks only insideevokeCallbackorevokeMultipleCallbacks. WithHLA_IMMEDIATEa thread of the client delivers them as they arrive.
Build and run
From hello-cpp:
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
-DFEDPRO_CPP="$PWD/../FedProClient/cpp" -DCMAKE_PREFIX_PATH="$PWD/../protobuf-install"
cmake --build build --parallelOn the Mac this was tested on, protobuf and then the client with the federate took about 20 seconds each.
Start an RTI in a terminal of its own:
microrti --listen tcp://127.0.0.1:0listening on tcp://127.0.0.1:64351Port 0 lets the system choose a free port, and the line says which one it chose. Without --listen,
microrti listens on 0.0.0.0:15164; 15164 is the standard Federate Protocol port.
A federate does not receive its own interactions, so run two. In a second terminal, from hello-cpp:
RTI=127.0.0.1:64351 # the address your microrti printed, without tcp://
./build/hello $RTI alice 20In a third terminal, within those 20 seconds:
./build/hello $RTI bob 3alice prints:
joined Chat as alice
<bob> hello from C++
left; the room is closedand bob prints:
joined Chat as bob
left; others are still in the roomalice heard bob; bob came after alice’s hello and heard nothing. The chat example of the
repository uses the same FOM module and federation execution name, so hello can talk to it, and to
the Java federate of Java federates:
Clients shows the three in one room.
Settings and logging
Settings of the client go into the additional settings of the configuration, with the prefix FedPro.
and separated by commas, or without the prefix into the environment variable FEDPRO_CLIENT_SETTINGS:
RtiConfiguration::createConfiguration()
.withRtiAddress(L"rti.example.org:15164")
.withAdditionalSettings(L"FedPro.connect.timeout=10")The client writes its log to the standard output, not to the standard error: warnings and errors by
default. FEDPRO_CLIENT_SETTINGS=log.console.level=info shows, among other things, the settings it used
for each connection. The settings and their defaults are listed in doc/Settings.md of FedProClient.
When it does not connect
Each of these was provoked against a local microrti; hello prints the name and the text of the
exception:
| Message | Cause |
|---|---|
ConnectionFailed: Failed to start FedPro session: Could not connect: Connection refused | Nothing listens at that address. |
RTIinternalError: Setting 'connect.port=//127.0.0.1' is invalid: ... | The address starts with tcp://. Give host:port only. |
ConnectionFailed: Failed to start FedPro session: Unimplemented transport type 'websocket' | FedPro.connect.protocol is not tcp. The C++ client has no other transport. |
CouldNotOpenFOM: could not open FOM module 'Chat.xml': not a URL: write a file:, http: or https: URL, or send the content of the module | Chat.xml is not in the directory hello runs from. The client then passes the name to the RTI, which reads no designator without a URL scheme, whatever its settings (FOM modules named by URL). |
Next steps
- Clients: how the other clients compare.
- Java federates: the same federate with the Java half of FedProClient, on any transport.
- Configure the RTI: listeners, transports and timeouts.
- The concepts of HLA, one by one: what federations, interactions and callbacks are.