bobermanager_web_logo

BoberManager C++ library

v2.0.0

Table of contents

Overview

The BoberManager C++ library is a UDP message manager designed to handle communication between multiple clients over a network. It uses UDP packets and string-based protocol. It operates on a static port 62000 and provides functionalities to manage client connections, relay messages, and respond to client queries. Key features include: • Client Management: maintains a list of connected clients and updates their addresses as needed. It allows clients communicate via ane gate. • Message Handling: receives and forwards messages between clients, ensuring proper routing based on source and destination identifiers. The BoberManager work together with BoberClient library which is used by applications for communication. • Request Responses: responds to specific client queries, such as requests for the list of connected clients. • Log Options: supports log options to print the list of clients, messages, or both for debugging and monitoring purposes. Communication structure:

bobermanager_principle

The library is built using C++17 and utilizes the UdpSocket library (provides methods to work with UDP sockets, source code included, Apache 2.0 license). Also the library’s repository includes application which can be run as communication manager. It is compatible with both Linux and Windows, with specific handling for closing processes on the designated port in Linux. Note: the BoberManager library retains a record of every client or service that has ever connected to it, even if the client disconnects. This information is preserved until the manager is shut down. The library doesn’t have any third-party dependency to be installed in OS.

Versions

Table 1 - Library versions.

Version Release date What’s new
1.0.0 10.04.2025 - First version of the application.
2.0.0 21.04.2025 - Application has been changed to library format.

Library files

The library is supplied by source code only. The user would be given a set of files in the form of a CMake project (repository). The repository structure is shown below:

CMakeLists.txt ---------------- Main CMake file of the library.
3rdparty ---------------------- Folder with third-party libraries.
    CMakeLists.txt ------------ CMake file to include third-party libraries.
    UdpSocket ----------------- Folder with UdpSocket library source code.
app --------------------------- Folder with the test application source code.
    CMakeLists.txt ------------ CMake file of the application.
    main.cpp ------------------ C++ source file of the application.
arc --------------------------- Folder with the library source code.
    CMakeLists.txt ------------ CMake file of the library.
    BoberManager.h ------------ Header file with BoberManager class declaration.
    BoberManager.cpp ---------- C++ implementation file.
    BoberManagerVersion.h ----- Header file which includes library version.
    BoberManagerVersion.h.in -- CMake service file to generate version header.

Message types

The BoberManager library supports different types of messages:

  1. Command - Used to send specific instructions or commands to another service or client. The receiver will send Ack message back if the message accepted or Nac packet if something wrong with message.
  2. Request - Used to request specific information or actions from another service or client. The receiver will send Response message back or Nac packet if something wrong with message.
  3. Response - Used to respond to a previously received Request message.
  4. Notify - Used to send notifications or updates to other services or clients. The receiver will send Ack message back.
  5. Ack - Acknowledgment message sent to confirm the successful receipt of a message. For Response there is not reply messages.
  6. Nack - Negative acknowledgment message sent to indicate an error or invalid message format. If the client for whom the message is intended is not in the list, the BoberManager sends the Nack message back.

Message format

The BoberManager library uses a specific message format for communication between clients. The format is as follows:

[<ID>]/Src:<source>/Dst:<destination>/<type>/<content>

: A unique identifier for the message. This helps in tracking and correlating messages. • : The source client name. This indicates the client that sent the message. • : The destination client name. This indicates the client that should receive the message. • : The type of message. This can be a request, response, or any other type of message defined by the application. • : The actual content of the message. This can be any data that needs to be communicated between clients.

Messages examples

  1. Client List Request:

       [121]/Src:ClientA/Dst:BoberManager/Request/Clients
    

    • [121]: Message ID • Src:ClientA: Source client is ClientA • Dst:BoberManager: Destination is BoberManager • Request/Clients: Requesting the list of connected clients Example response:

       [121]/Src:BoberManager/Dst:ClientA/Response/Clients:ClientB,ClientC
    
  2. Request parameter message to Another Client:

       [122]/Src:ClientA/Dst:ClientB/Request/Contrast
    

    • [122]: Message ID • Src:ClientA: Source client is ClientA • Dst:ClientB: Destination client is ClientB • Request/Contrast: Requesting Contrast parameter from ClientB Example response:

       [122]/Src:ClientB/Dst:ClientA/Response/Contrast:50
    
  3. Command message to set parameter value message to Another Client:

       [123]/Src:ClientA/Dst:ClientB/Command/Contrast:78
    

    • [123]: Message ID • Src:ClientA: Source client is ClientA • Dst:ClientB: Destination client is ClientB • Command/Contrast:78: Calling command to set parameter value Example response:

       [123]/Src:ClientB/Dst:ClientA/Ack
    

BoberManager class description

BoberManager class declaration

BoberManager class declared in BoberManager.h file. Class declaration:

namespace cr
{
namespace bober
{
/// Bober Manager class.
class BoberManager
{
public:

    /// Get version.
    static std::string getVersion();

    /// Run Bober Manager.
    bool run(bool printClients, bool printMessages);

    /// Stop Bober Manager.
    void stop();
};
}
}

getVersion method

The getVersion() method returns string of current class version. Method declaration:

static std::string getVersion();

Method can be used without BoberManager class instance:

std::cout << "BoberManager v: " << cr::bober::BoberManager::getVersion();

Console output:

BoberManager v: 2.0.0

run method

The run(…) method initializes BoberManager library. The method will open 62000 port will start operation. Note: for Linux the method will close all applications which use 62000 port (the application must run from sudo). This is blocking method. It will return FALSE if not initialized and will block while running well. Method declaration:

bool run(bool printClients, bool printMessages);
Parameter Value
printClients If TRUE the method will print list of clients connected.
printMessages If TRUE the method will print all messages.

Returns: TRUE if the UDP port open or FALSE if not.

stop method

The stop(…) method stops run(…) method execution. After calling stop(…) method the run(…) method will stop execution (will return control). Method declaration:

void stop();

Example

The example shows how to make application based on BoberManager class:

#include <iostream>
#include "BoberManager.h"

int main(int argc, char** argv)
{
    cr::bober::BoberManager boberManager;
    std::cout << "BoberManager v" << cr::bober::BoberManager::getVersion() << std::endl;

    // Check manual run command.
    bool printClients = false;
    bool printMessages = false;
    if (argc > 1)
    {
        if (std::string(argv[1]) == "-p")
        {
            printClients = true;
        }
        else if (std::string(argv[1]) == "-m")
        {
            printMessages = true;
        }
        else if (std::string(argv[1]) == "-pm")
        {
            printClients = true;
            printMessages = true;
        }
        else if (std::string(argv[1]) == "-h")
        {
            std::cout << "Usage: " << argv[0] << " [-p | -m | -pm]" << std::endl;
            std::cout << "  -p  Print clients list." << std::endl;
            std::cout << "  -m  Print messages." << std::endl;
            std::cout << "  -pm Print clients list and messages." << std::endl;
            return 0;
        }
        else
        {
            std::cerr << "Invalid argument. Use -p for clients list or -m for messages." << std::endl;
            return 0;
        }
    }

    // Init and run BoberManager.
    if (!boberManager.run(printClients, printMessages))
    {
        std::cerr << "Failed to run BoberManager." << std::endl;
        return 0;
    }

    return 0;
}

Build and connect to your project

Typical commands to build BoberManager library (on Linux OS):

cd BoberManager
mkdir build
cd build
cmake ..
make

If you want connect BoberManager library to your CMake project as source code you can make follow. For example, if your repository has structure:

CMakeLists.txt
src
    CMakeList.txt
    yourLib.h
    yourLib.cpp

Create 3rdparty folder in your repository and copy BoberManager repository folder there. New structure of your repository:

CMakeLists.txt
src
    CMakeList.txt
    yourLib.h
    yourLib.cpp
3rdparty
    BoberManager

Create CMakeLists.txt file in 3rdparty folder. CMakeLists.txt should contain:

cmake_minimum_required(VERSION 3.13)

################################################################################
## 3RD-PARTY
## dependencies for the project
################################################################################
project(3rdparty LANGUAGES CXX)

################################################################################
## SETTINGS
## basic 3rd-party settings before use
################################################################################
# To inherit the top-level architecture when the project is used as a submodule.
SET(PARENT ${PARENT}_YOUR_PROJECT_3RDPARTY)
# Disable self-overwriting of parameters inside included subdirectories.
SET(${PARENT}_SUBMODULE_CACHE_OVERWRITE OFF CACHE BOOL "" FORCE)

################################################################################
## INCLUDING SUBDIRECTORIES
## Adding subdirectories according to the 3rd-party configuration
################################################################################
add_subdirectory(BoberManager)

File 3rdparty/CMakeLists.txt adds folder BoberManager to your project and excludes examples from compiling (by default examples excluded from compiling if BoberManager included as sub-repository). Your repository new structure will be:

CMakeLists.txt
src
    CMakeList.txt
    yourLib.h
    yourLib.cpp
3rdparty
    CMakeLists.txt
    BoberManager

Next you need include folder 3rdparty in main CMakeLists.txt file of your repository. Add string at the end of your main CMakeLists.txt:

add_subdirectory(3rdparty)

Next you have to include BoberManager library in your src/CMakeLists.txt file:

target_link_libraries(${PROJECT_NAME} BoberManager)

Done!


Table of contents