chrberger / libcluon

libcluon is a small and efficient, single-file and header-only library written in modern C++ to power microservices.
Mozilla Public License 2.0
99 stars 13 forks source link

How can one efficiently transmit substantial volumes of data? #23

Closed leielyq closed 9 months ago

leielyq commented 9 months ago

How can one efficiently transmit substantial volumes of data?

`using namespace std;

int main() { cout << "Hello CMake." << endl;

cluon::OD4Session od4{ 100 };

if (od4.isRunning()) {
    // Let's wait for 5s before start sending our message.
    using namespace std::chrono_literals;
    std::this_thread::sleep_for(1s);
    int count = 0;
    std::vector<uint8_t> data;
    data.resize(1024 *1024);
    int index = 0;
    for(auto& item : data)
    {
        item = index++ % 255;
    }
    // Let's create our message and set some values.
    MyMessage1 msg;
    msg.myNumber(count)
        .data(std::string(data.begin(), data.end()))
        .myText("Hello World!");

    //// Finally, send the message.
    while (true)
    {
        msg.myNumber(count++);
        od4.send(msg);
    }

}

return 0;

} `

chrberger commented 9 months ago

The OD4 session is encapsulating data via UDP packets. To exchange larger volumes beyond UDP packet sizes via IPC on the same system, you can look into libcluon's portable SharedMemory abstraction: https://wandbox.org/permlink/m7bmtpOS0dynGJlP