UdpDataChannel C++ lib. Point-to-point reliable communication between applications using UDP

€30.00

UdpDataChannel C++ library version 1.2.1 provide reliable point-to-point communication between two applications based on UDP.

We sell source code of this library as is, without future updates and technical support according to perpetual non-exclusive royalty-free license. You pay once and can use this library in your software and hardware products without limits. Please read the license agreement before purchasing: LICENSE. You can buy technical support service for this product.

Add To Cart

UdpDataChannel C++ library version 1.2.1 provide reliable point-to-point communication between two applications based on UDP.

We sell source code of this library as is, without future updates and technical support according to perpetual non-exclusive royalty-free license. You pay once and can use this library in your software and hardware products without limits. Please read the license agreement before purchasing: LICENSE. You can buy technical support service for this product.

Technical support service
Options:

UdpDataChannel C++ library version 1.2.1 provide reliable point-to-point communication between two applications based on UDP.

We sell source code of this library as is, without future updates and technical support according to perpetual non-exclusive royalty-free license. You pay once and can use this library in your software and hardware products without limits. Please read the license agreement before purchasing: LICENSE. You can buy technical support service for this product.

Purchase options

You can buy the software by bank transfer. Bank transfer available only for companies. To buy software by bank transfer please send us request to info@constantrobotics.com. Also, you can buy technical support service for this product.

Overview

UdpDataChannel C++ library provides point-to-point communication between two applications based on UDP. The library includes two main classes: UdpDataClient (connects to server) and UdpDataServer (wait connection from client). Both classes provide two-way communication. The library uses C++17 standard and only depends on open source UdpSocket (source code included, Apache 2.0 license) which provide functions to work with UDP sockets. This library compatible with Linux and Window. Server principles: the server initializes the user-specified UDP port and waits for the client to connect from any port. The server supports connection of only one client. When a client connects the server remembers the client's IP and UDP port to exchange messages with them. The client sends special commands to connect. Client principles: the client initialized any first available UDP port in the OS. After initialization client sends connection messages to server port (to connect the user must say to client the server's UDP port and IP). Once connection established the client can exchanges messages with server. To send data server and client split data into separate UDP packets with special header data. Receiver (client or server) collect UDP packets and detect when whole input data being send by sender collected. After receiver sends confirmation. Sender sends data twice until it will get confirmation from receiver. The library can handle intensive data exchange close to channel bandwidth limit. The library allows user to set maximum channel bandwidth to prevent network overloading. Sender (client or server) controls interval between UDP packets being sent.andwidth limit. The library allows user to set maximum channel bandwidth to prevent network overloading. Sender (client or server) controls interval between UDP packets being sent.

Simple example for client and server

#include <iostream>
#include <thread>
#include <cstdint>
#include "UdpDataChannel.h"

void serverThreadFunction()
{
    // Init server.
    cr::clib::UdpDataServer server;
    if (!server.init(58002))
    {
        std::cout << "Can't init server" << std::endl;
        return;
    }

    // Thread loop.
    uint8_t buffer[256];
    while (true)
    {
        // Wait data from client for 2 sec.
        int size = 0;
        if (!server.get(buffer, 256, size, 2000))
        {
            std::cout << "No input data from client" << std::endl;
            continue;
        }

        // Send data back to client.
        if (!server.send(buffer, size))
            std::cout << "Can't send data to client" << std::endl;
    }
}

int main(void)
{
    // Run server thread.
    std::thread serverThread(&serverThreadFunction);

    // Init client.
    cr::clib::UdpDataClient client;
    if (!client.init("127.0.0.1", 58002))
    {
        std::cout << "Can't init client" << std::endl;
        return -1;
    }

    // Main loop.
    uint8_t buffer[256];
    while (true)
    {
        // Prepare random data for server.
        int size = (rand() % 128) + 1;
        memset(buffer, (rand() % 255), size);
        std::cout << std::endl;

        // Send data to server.
        if (!client.send(buffer, size))
            std::cout << "Can't send data to server" << std::endl;
        else
            std::cout << size << " bytes to server" << std::endl;

        // Wait data from server.
        size = 0;
        if (!client.get(buffer, 256, size, 2000))
            std::cout << "No input data from server" << std::endl;
        else
            std::cout << size << " bytes from server" << std::endl;
    }

    return 1;
}

Downloads

Programmer’s manual: DOWNLOAD

Simple interface

UdpDataClient class declared in UdpDataChannel.h file:

namespace cr
{
namespace clib
{
/// UDP data client class.
class UdpDataClient
{
public:

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

    /// Class constructor.
    UdpDataClient();

    /// Class destructor.
    ~UdpDataClient();

    /// Initialize client with server's address and port.
    bool init(std::string serverIp, uint16_t serverPort,
              int channelBandwidthKbps = 1000000);

    /// Close client.
    void close();

    /// Get input data from connected client.
    bool get(uint8_t* data, int bufferSize, int& dataSize, int timeoutMsec = 0);

    /// Send data to the client.
    bool send(uint8_t* data, int size);

    /// Get connection status.
    bool isConnected();

    /// Get channel status.
    bool isInit();
};
}
}

UdpDataServer class declared in UdpDataChannel.h file:

namespace cr
{
namespace clib
{
/// UDP data server class.
class UdpDataServer
{
public:

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

    /// Class constructor.
    UdpDataServer();

    /// Class destructor.
    ~UdpDataServer();

    /// Initialize server with port number and bandwidth.
    bool init(uint16_t port, int channelBandwidthKbps = 1000000);

    /// Close server.
    void close();

    /// Get input data from connected client.
    bool get(uint8_t* data, int bufferSize, int& dataSize, int timeoutMsec = 0);

    /// Send data.
    bool send(uint8_t* data, int size);

    /// Get connection status.
    bool isConnected();

    /// Get channel status.
    bool isInit();
};
}
}
Joystick C++ lib. Simple cross-platform library to work with joysticks
€20.00
NtpUdpChannel C++ lib. Point-to-point communication based on UDP for low bandwidth channels
€10.00