RepliconChannels is a resource that manages the communication channels used by Replicon. It distinguishes between channels used for sending and receiving based on whether the application is running as a client or a server.
Directionality
- On a Client:
RepliconChannels::client_channels() are used for sending data to the server.RepliconChannels::server_channels() are used for receiving data from the server.
- On a Server:
RepliconChannels::server_channels() are used for sending data to clients.RepliconChannels::client_channels() are used for receiving data from clients.
Note: If your backend does not distinguish between sending and receiving, you should create channels for both client and server by chaining them.
Custom Channels
Backends can define their own channels by writing an extension trait for RepliconChannels. Any custom channels created should have a delivery guarantee equal to or stronger than the ones they are replacing.
Reserved Channels
Replicon uses specific reserved channels for core replication logic:
Server-to-Client (ServerChannel)
ServerChannel::Updates: An ordered reliable channel used for entity mappings, inserts, removals, and despawns. This ensures atomic updates and prevents outdated state.ServerChannel::Mutations: An unreliable channel used for component mutations. This allows for eventual consistency where the latest values are prioritized over missing intermediate ticks.
Client-to-Server (ClientChannel)
ClientChannel::MutationAcks: An ordered reliable channel used by the client to acknowledge mutation messages received via ServerChannel::Mutations.
Channel Delivery Guarantees
All channels are defined by a Channel type specifying their reliability and ordering:
Channel::Unreliable: Unreliable and unordered.Channel::Unordered: Reliable and unordered.Channel::Ordered: Reliable and ordered.
// Example of accessing channels (conceptual usage)
fn check_channels(channels: Res<RepliconChannels>) {
let server_to_client = channels.server_channels();
let client_to_server = channels.client_channels();
}