Skip to content

ryu_ldn::network::RyuLdnClient

High-level RyuLdn network client.

This is the main client class that applications should use to communicate withservers. It handles all the complexity of connection management, state tracking, and protocol handling.LifecycleCreate client with configurationSet up callbacks for state changes and packetsCallto initiate connectionCallregularly to process eventsSend packets whenreturns trueCallwhen doneclassryu__ldn_1_1network_1_1RyuLdnClient_1State TransitionsThe client maintains an internal state machine:: Initial state, callto start: TCP connection in progress: TCP connected, handshake starting: Protocol handshake in progress: Fully connected and operational: Waiting before retry after failure: Retry attempt in progress: Graceful disconnect in progress: Fatal error, calland retryclassryu__ldn_1_1network_1_1RyuLdnClient_1

Type: RyuLdnClientConfig

Client configuration.

Type: TcpClient

Low-level TCP client.

Type: ConnectionStateMachine

Connection state tracking.

Type: ReconnectManager

Reconnection backoff logic.

Type: ClientStateCallback

User callback for state changes.

Type: ClientPacketCallback

User callback for packets.

Type: void *

User data for packet callback.

Type: uint64_t

Time of last ping sent.

Type: uint64_t

Start of current backoff period.

Type: uint32_t

Current backoff delay.

Type: protocol::SessionId

Our session ID (from server)

Type: protocol::MacAddress

Our MAC address.

Type: bool

Whether Initialize has been sent.

Type: bool

Whether socket system is initialized.

Type: uint64_t

Time when handshake was initiated.

Type: uint32_t

Handshake timeout (default: 5000ms)

Type: protocol::NetworkErrorCode

Last error from server.

Type: uint64_t

Time when last pong was received.

Type: uint32_t

Ping response timeout (default: 10000ms)

Type: uint32_t

Number of pings without response.

Type: uint64_t

Last measured round-trip time.

Type: uint8_t

Incrementing ping ID for tracking.

void RyuLdnClient()

Constructor with default configuration.

Creates a client with default settings. Callbefore connecting to customize behavior.Creates a client ready to connect.initialization is deferred until first connection attempt.

void RyuLdnClient(const& config)

Constructor with custom configuration.

configClient configurationconfigClient configuration including server addressparam

Parameters:

  • config (const&)
void ~RyuLdnClient()

Destructor - ensures clean disconnect.

Disconnects from server if connected and cleans up resources.

void RyuLdnClient(const&)

Parameters:

  • param (const&)
& operator=(const&)

Parameters:

  • param (const&)

Returns: &

void RyuLdnClient(&& other)

Move constructor.

Transfers ownership of all resources from other client.otherSource client to move fromparam

Parameters:

  • other (&&)
& operator=(&& other)

Move assignment operator.

otherSource client to move fromparamReference to thisreturn

Parameters:

  • other (&&)

Returns: &

void set_config(const& config)

Update client configuration.

Can be called while disconnected to change settings.configNew configurationconfigNew configuration to useparam

Parameters:

  • config (const&)
const& get_config()

Get current configuration.

Reference to current configurationreturn

Returns: const&

void set_state_callback(ClientStateCallback callback)

Set callback for state changes.

callbackFunction to call on state change (nullptr to disable)callbackFunction to call when state changesparam

Parameters:

  • callback (ClientStateCallback)
void set_packet_callback(ClientPacketCallback callback, void * user_data)

Set callback for received packets.

callbackFunction to call on packet receive (nullptr to disable)user_dataUser-provided context pointer passed to callbackcallbackFunction to call for each received packetuser_dataUser-provided context pointer passed to callbackparam

Parameters:

  • callback (ClientPacketCallback)
  • user_data (void *)
ClientOpResult connect()

Initiate connection to server.

Starts the connection process. The connection is asynchronous - callregularly and checkor use the state callback to know when connected.Uses host/port from configuration.ClientOpResult indicating success or failurereturn

Returns: ClientOpResult

ClientOpResult connect(const char * host, uint16_t port)

Initiate connection with specific host/port.

Overrides configuration for this connection attempt.Updates configuration and starts connection process.hostServer hostname or IP addressportServer port numberparamClientOpResult indicating success or failurereturn

Parameters:

  • host (const char *)
  • port (uint16_t)

Returns: ClientOpResult

void disconnect()

Gracefully disconnect from server.

Disconnect from server.Sends disconnect message and closes connection.Sends disconnect message (if connected) and closes connection.

void update(uint64_t current_time_ms)

Update client - must be called regularly.

This method:Call this from your main loop, ideally every frame or tick.Handles all client maintenance tasks.current_time_msCurrent time in millisecondsparam

Parameters:

  • current_time_ms (uint64_t)
ConnectionState get_state()

Get current connection state.

Current statereturn

Returns: ConnectionState

bool is_connected()

Check if connected (TCP established)

true if TCP is connected (may not be ready for packets)returntrue if TCP is connectedreturn

Returns: bool

bool is_ready()

Check if fully ready (handshake complete)

Check if fully ready.true if ready to send/receive packetsreturn

Returns: bool

bool is_transitioning()

Check if in transitional state.

true if connecting, disconnecting, or in backoffreturn

Returns: bool

uint32_t get_retry_count()

Get retry count since last successful connection.

Get retry count.Number of connection attemptsreturn

Returns: uint32_t

protocol::NetworkErrorCode get_last_error_code()

Get last error code from server.

Returns the error code from the most recent NetworkError message. Useful for diagnosing connection failures.Last error code (NetworkErrorCode::None if no error)returnLast error code (NetworkErrorCode::None if no error)return

Returns: protocol::NetworkErrorCode

uint64_t get_last_rtt_ms()

Get last measured round-trip time.

Returns the RTT from the most recent ping/pong exchange. Useful for monitoring connection quality.RTT in milliseconds (0 if no ping completed yet)returnRTT in milliseconds (0 if no ping completed yet)return

Returns: uint64_t

ClientOpResult send_scan(const protocol::ScanFilterFull & filter)

Send a scan request to find networks.

Send scan request.filterScan filter parametersparamClientOpResult indicating success or failurereturn

Parameters:

  • filter (const protocol::ScanFilterFull &)

Returns: ClientOpResult

ClientOpResult send_create_access_point(const protocol::CreateAccessPointRequest & request)

Send request to create an access point.

Send create access point request.requestAccess point parametersparamClientOpResult indicating success or failurereturn

Parameters:

  • request (const protocol::CreateAccessPointRequest &)

Returns: ClientOpResult

ClientOpResult send_connect(const protocol::ConnectRequest & request)

Send request to connect to a network.

Send connect request.requestConnection parametersparamClientOpResult indicating success or failurereturn

Parameters:

  • request (const protocol::ConnectRequest &)

Returns: ClientOpResult

ClientOpResult send_create_access_point_private(const protocol::CreateAccessPointPrivateRequest & request)

Send request to create a private access point.

Send create access point private request.requestAccess point parameters with security settingsparamClientOpResult indicating success or failurereturn

Parameters:

  • request (const protocol::CreateAccessPointPrivateRequest &)

Returns: ClientOpResult

ClientOpResult send_connect_private(const protocol::ConnectPrivateRequest & request)

Send request to connect to a private network.

Send connect private request.requestConnection parameters with security settingsparamClientOpResult indicating success or failurereturn

Parameters:

  • request (const protocol::ConnectPrivateRequest &)

Returns: ClientOpResult

ClientOpResult send_proxy_data(const protocol::ProxyDataHeader & header, const uint8_t * data, size_t size)

Send proxy data to another client.

Send proxy data.headerProxy header with destination infodataData to sendsizeSize of dataparamheaderProxy headerdataData to sendsizeSize of dataparamClientOpResult indicating success or failurereturnClientOpResult indicating success or failurereturn

Parameters:

  • header (const protocol::ProxyDataHeader &)
  • data (const uint8_t *)
  • size (size_t)

Returns: ClientOpResult

ClientOpResult send_ping()

Send a ping to keep connection alive.

Send ping.Normally called automatically by, but can be called manually if needed.ClientOpResult indicating success or failurereturnClientOpResult indicating success or failurereturn

Returns: ClientOpResult

ClientOpResult send_ping_response(uint8_t ping_id)

Send a ping response to echo back a server ping.

ping_idThe ping ID from the server’s ping requestparamClientOpResult indicating success or failurereturn

Parameters:

  • ping_id (uint8_t)

Returns: ClientOpResult

ClientOpResult send_disconnect_network()

Send disconnect notification to server.

Notifies the server that we’re leaving the network.ClientOpResult indicating success or failurereturn

Returns: ClientOpResult

ClientOpResult send_set_accept_policy(protocol::AcceptPolicy policy)

Send SetAcceptPolicy request (host only)

Changes the accept policy for new connections.policyNew accept policyparamClientOpResult indicating success or failurereturn

Parameters:

  • policy (protocol::AcceptPolicy)

Returns: ClientOpResult

ClientOpResult send_set_advertise_data(const uint8_t * data, size_t size)

Send SetAdvertiseData request (host only)

Updates the advertise data for the network.dataAdvertise data buffersizeSize of data (max 384 bytes)paramClientOpResult indicating success or failurereturn

Parameters:

  • data (const uint8_t *)
  • size (size_t)

Returns: ClientOpResult

ClientOpResult send_reject(uint32_t node_id, protocol::DisconnectReason reason)

Send Reject request (host only)

Rejects/kicks a player from the network.node_idNode ID of player to rejectreasonDisconnect reasonparamClientOpResult indicating success or failurereturn

Parameters:

  • node_id (uint32_t)
  • reason (protocol::DisconnectReason)

Returns: ClientOpResult

ClientOpResult send_raw_packet(const void * data, size_t size)

Send raw pre-encoded packet.

Sends a packet that has already been encoded. Used by P2P components to forward notifications to the master server.dataEncoded packet datasizePacket sizeparamClientOpResult indicating success or failurereturn

Parameters:

  • data (const void *)
  • size (size_t)

Returns: ClientOpResult

void state_machine_callback(ConnectionState old_state, ConnectionState new_state, ConnectionEvent event)

Handle state machine callback.

Parameters:

  • old_state (ConnectionState)
  • new_state (ConnectionState)
  • event (ConnectionEvent)
void try_connect()

Attempt TCP connection.

Called when state machine enters Connecting or Retrying state.

void process_packets()

Process received packets.

Polls TCP client for packets and handles each one.

void handle_packet(protocol::PacketId id, const uint8_t * data, size_t size)

Handle a single received packet.

idPacket typedataPacket payloadsizePayload sizeparam

Parameters:

  • id (protocol::PacketId)
  • data (const uint8_t *)
  • size (size_t)
ClientOpResult send_initialize()

Send Initialize handshake message.

ClientOpResult indicating success or failurereturn

Returns: ClientOpResult

bool process_handshake_response(protocol::PacketId id, const uint8_t * data, size_t size)

Process handshake response.

Process handshake response from server.Called when in Handshaking state to process server response.Handles the server’s response to our Initialize message. The RyuLDN server responds with an Initialize packet containing:This matches the official Ryujinx client behavior.idPacket ID receiveddataPacket datasizePacket sizeparamtrue if handshake completed (success or failure)return

Parameters:

  • id (protocol::PacketId)
  • data (const uint8_t *)
  • size (size_t)

Returns: bool

bool is_handshake_timeout(uint64_t current_time_ms)

Check if handshake has timed out.

current_time_msCurrent time in millisecondsparamtrue if handshake timeout has elapsedreturn

Parameters:

  • current_time_ms (uint64_t)

Returns: bool

void generate_mac_address()

Generate a unique MAC address.

Generates a locally administered MAC address. Format: X2:XX:XX:XX:XX:XX where X2 indicates locally administered.

void start_backoff()

Start backoff timer.

Records the current time and calculates backoff delay.

bool is_backoff_expired(uint64_t current_time_ms)

Check if backoff has expired.

current_time_msCurrent time in millisecondsparamtrue if backoff period has elapsedreturn

Parameters:

  • current_time_ms (uint64_t)

Returns: bool