#include <iostream>
#include <string>
{
std::cout << "=== Unified Messaging Interface Example ===" << std::endl;
std::cout << "\n1. Endpoint configuration:" << std::endl;
server_endpoint.
host =
"0.0.0.0";
server_endpoint.
port = 9090;
client_endpoint.
host =
"localhost";
client_endpoint.
port = 9090;
std::cout <<
" Server: " << server_endpoint.
host <<
":" << server_endpoint.
port << std::endl;
std::cout <<
" Client: " << client_endpoint.
host <<
":" << client_endpoint.
port << std::endl;
std::cout << "\n2. Setting up connection callbacks:" << std::endl;
{ std::cout << " [Callback] Connected!" << std::endl; };
callbacks.
on_data = [](std::span<const std::byte> data)
{ std::cout << " [Callback] Received " << data.size() << " bytes" << std::endl; };
{
std::cout << " [Callback] Disconnected";
if (reason)
{
std::cout << ": " << *reason;
}
std::cout << std::endl;
};
callbacks.
on_error = [](std::error_code ec)
{ std::cout << " [Callback] Error: " << ec.message() << std::endl; };
std::cout << " All 4 callbacks configured (on_connected, on_data, "
<< "on_disconnected, on_error)" << std::endl;
std::cout << "\n3. Unified interface hierarchy:" << std::endl;
std::cout << " i_transport - send(), is_connected(), remote_endpoint()" << std::endl;
std::cout << " i_connection - connect(), close(), set_callbacks()" << std::endl;
std::cout << " i_listener - start(), stop(), set_accept_callback()" << std::endl;
std::cout << "\n Use with protocol tags:" << std::endl;
std::cout << " unified_messaging_client<tcp_protocol, no_tls>" << std::endl;
std::cout << " unified_messaging_server<tcp_protocol, tls_enabled>" << std::endl;
std::cout << "\nDone." << std::endl;
return 0;
}
Main namespace for all Network System components.
Callback functions for connection events.
std::function< void()> on_disconnected
Called when connection is closed.
std::function< void(std::span< const std::byte >)> on_data
Called when data is received (raw bytes)
std::function< void()> on_connected
Called when connection is established.
std::function< void(std::error_code)> on_error
Called when an error occurs.
Network endpoint information (host/port or URL)
std::string host
Hostname, IP address, or full URL.
uint16_t port
Port number (0 if embedded in URL)
Convenience header for the unified network interface API.