MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TCPBackend Class Reference

Reliable length-prefixed message transport over TCP via standalone Asio. More...

#include <TCPBackend.hpp>

Collaboration diagram for TCPBackend:

Detailed Description

Reliable length-prefixed message transport over TCP via standalone Asio.

Two endpoint modes:

  • Outbound (remote_address set): async_connect to a remote host.
  • Listener (local_port set, no remote_address): async_accept on a port. Accepted connections become new endpoints, announced via state callback.

Framing: every message on the wire is [uint32_t network-order length][payload]. The backend handles framing transparently. Callers send and receive complete messages, never partial streams.

Reconnection: if auto_reconnect is enabled and a connection drops, the backend transitions to RECONNECTING and schedules async_connect retries via asio::steady_timer.

All I/O is async on the shared io_context. See StreamBackend for the shared behaviour.

asio::io_context ctx;
TCPBackend tcp(config, ctx);
tcp.initialize();
tcp.set_receive_callback([](uint64_t id, const uint8_t* d, size_t s, std::string_view a) {
// handle complete framed message
});
tcp.set_state_callback([](const EndpointInfo& ep, EndpointState prev, EndpointState cur) {
// track connection/disconnection
});
tcp.start();
// Outbound connection
EndpointInfo client_ep;
client_ep.role = EndpointRole::BIDIRECTIONAL;
client_ep.remote_address = "192.168.1.50";
client_ep.remote_port = 7000;
auto ep_id = tcp.open_endpoint(client_ep);
// Listener
EndpointInfo server_ep;
server_ep.role = EndpointRole::RECEIVE;
server_ep.local_port = 7000;
auto listen_id = tcp.open_endpoint(server_ep);
ctx.run();
Reliable length-prefixed message transport over TCP via standalone Asio.

The documentation for this class was generated from the following file: