public sealed class BroadcastRouterTyped messages that are not about a networked object.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
Why this is not an RPC. A remote call is about an object: it names one, ownership and the rules are checked against it, and it is refused if the receiver does not have it. Chat, a match-start countdown, a scoreboard, a "loading finished" from each client, a server telling everyone the round is over — none of those are about an object, and inventing one to hang them from means every such message needs a spawned entity, ownership and an interest set that all exist only to satisfy the dispatcher.
So a broadcast has its own payload kind and its own closed registry. What it keeps from the RPC path is everything that made that path safe: a message names a position in a registry rather than a type, so a packet can never be talked into constructing something; the sender is what the session says it is, never what the packet claims; and a handler that throws does not take the receive loop with it.
Rate limiting is deliberately the caller's. A broadcast from a client is exactly as abusable as a server RPC, and the token bucket that already exists lives in RpcRouter — sharing it would mean either coupling the two or duplicating it. A server that accepts client broadcasts should give this a limiter; one that only sends them does not need it. See Limits.
Fields and properties (6)
public BroadcastLimits? LimitsHow many broadcasts a connection may send. Null to not limit them.
public int RegisteredCountHow many message types are registered.
public long DeliveredCountMessages that were delivered to a handler.
public long RefusedByRegistryCountMessages refused because the id names nothing registered.
public long RefusedByPayloadCountMessages refused because they did not decode, or left bits behind.
public long RefusedByRateLimitCountMessages refused because the sender is sending too many.
Methods (7)
public BroadcastRouter(int maxPayloadBytes = 1200)Creates a router.
public void Subscribe<T>(Action<PlayerId, T> handler) where T : struct, IBroadcast<T>Starts accepting a message type, and says what to do with one.
public bool TryEncode<T>(in T message, out ReadOnlySpan<byte> payload) where T : struct, IBroadcast<T>Encodes a message, ready to hand to a session.
public bool Receive(PlayerId from, ReadOnlySpan<byte> payload)Takes a broadcast off the wire, checks it, and hands it to whoever asked.
public void Advance(TimeSpan elapsed)Refills the rate limiters.
public void Forget(PlayerId player)Forgets a connection's rate-limit state.
public static uint Identify<T>() where T : struct, IBroadcast<T>The wire id a message type has.
Used by (2)
- BroadcastTestsVixen.Net.Tests
- PredictionWiringTestsVixen.Net.Tests