Suduxu
API

Events System

Suduxu uses an event-driven architecture to communicate runtime state, input, device updates, and diagnostics across all connected clients.

Suduxu is built around a centralized event system. The native runtime emits structured events that are dispatched into typed channels on the host side (Rust, Unity, or other bindings) — these are the primary mechanism for reacting to runtime behavior.


Event categories

TCP

Connection lifecycle and errors.

UDP

Input, sensor data, and screenshots.

State

Battery, network, and health.

Log

Diagnostics and debugging.

Event flow

Emit

The native layer serializes an event as JSON.

Cross the FFI boundary

The JSON payload is passed through an FFI callback.

Deserialize

The payload becomes a typed EventObject.

Dispatch

The object is routed to its specific handler.


TCP events

Prop

Type

ON_CLIENT_CONNECTED.subscribe(|id| {
    println!("Client connected: {}", id);
});

See Reference/Data-Models for details on the Payload data model.

Prop

Type

suduxu.Server.OnClientConnected += id =>
{
    Debug.Log($"Client connected: {id}");
};

See Reference/Data-Models for details on the Payload data model.


UDP events

Real-time device input and sensor data.

Prop

Type

ON_SENSOR_DATA.subscribe(|data| {
    println!("Received sensor data: {:?}", data);
});

See Reference/Data-Models for details on the SensorDataRaw, ButtonInput, and JoystickData data models.

Prop

Type

suduxu.Input.Broadcast().OnSensorData += data =>
{
    Debug.Log($"Received sensor data: {data}");
};

Input events that take an id parameter (including OnSensorData) only trigger for the client matching that id. Use broadcast events for global input handling.

See Reference/Data-Models for details on the SensorDataRaw, ButtonInput, and JoystickData data models.


State events

Continuous device telemetry — battery, network, and health.

Prop

Type

ON_BATTERY_CHANGE.subscribe(|(id, battery)| {
    println!("Client {} battery changed: {:?}", id, battery);
});

See Reference/Data-Models for details on the Battery and Network data models.

Prop

Type

suduxu.Client.Broadcast().OnBatteryChange += (id, battery) =>
{
    Debug.Log($"Client {id} battery changed: {battery}");
};

State events that take an id parameter only trigger for the client matching that id. Use broadcast events for global state handling.

See Reference/Data-Models for details on the Battery and Network data models.


Log events

Emitted from both native and client-side systems.

ON_LOG.subscribe(|log| {
    println!("Log: {:?}", log);
});
suduxu.Log.OnLog += (log) =>
{
    Debug.Log($"Log: {log}");
};

Event rules

Events are asynchronous, and delivery order isn't guaranteed across categories — TCP events cover connection lifecycle only, UDP events are real-time input streams, state events reflect periodic updates, and health events may lag behind an actual disconnect due to the timeout window.

Events are only valid after the runtime has launched — subscribing before initialization may miss early emissions.

In Unity, the suduxu object must be injected before use:

public class SuduxuExample : MonoBehaviour {
  [injected]
  private Suduxu suduxu;
}

Or accessed directly:

Suduxu.Instance

On this page