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

€50.00

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

LICENSE: 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: DOWNLOAD LICENSE. You can buy technical support service for this product.

Add To Cart
Technical support service
Options:

Purchase options

You can by this software online by card or 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 provide reliable point-to-point communication between two applications based on UDP. The library includes two primary 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.

Downloads

Programmer’s manual: DOWNLOAD

Simple interface

class UdpDataServer
{
public:

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

    /// Close server. Complete all open threads and clear data buffers.
    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();
};

Simple example for client and server

#include <iostream>
#include <thread>
#include <cstdint>
#include "UdpDataServer.h"
#include "UdpDataClient.h"

void serverThreadFunction()
{
    // Init server.
    cr::clib::UdpDataServer server;
    if (!server.init(57000))
        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;

        // 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", 57000))
        return -1;

    // Main loop.
    uint8_t buffer[256];
    while (true)
    {
        // Wait data from server.
        int 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;

        // Prepare random data for server.
        size = (rand() % 128) + 1;
        memset(buffer, (rand() % 255), size);

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

    return 1;
}
NtpUdpChannel C++ lib. Point-to-point communication based on UDP for low bandwidth channels
€10.00
Joystick C++ lib. Simple cross-platform library to work with joysticks
€20.00