pub struct TokioSoeServer { /* private fields */ }Expand description
An actor-style SOE server: a SoeMultiplexer driven on its own Tokio task,
reachable from any task via a cloneable SoeHandle.
This is the recommended shape for a game server. The driver task owns the UDP socket and all protocol state (sequence numbers, ciphers, reassembly), which is inherently single-owner. Application code interacts with it asynchronously:
- Obtain a cloneable
SoeHandlewithhandleand share it with per-client game-logic tasks to send data or manage sessions. - Receive
SocketEvents withrecv_eventand route them (e.g. fanDataReceivedout to the matching per-client task).
Because each server owns one socket and one multiplexer, scaling UDP I/O across
cores later is a matter of running several servers — one per SO_REUSEPORT
socket — and routing by client address; no change to the core is required.
The driver task runs until the TokioSoeServer and every SoeHandle are
dropped, or until the event receiver is dropped.
Implementations§
Source§impl TokioSoeServer
impl TokioSoeServer
Sourcepub async fn bind(
local: SocketAddr,
config: SocketConfig,
tick_period: Duration,
) -> Result<Self>
pub async fn bind( local: SocketAddr, config: SocketConfig, tick_period: Duration, ) -> Result<Self>
Binds a UDP socket to local and spawns the driver loop, ticking every
tick_period. A period of 1–10ms is typical.
Sourcepub fn local_addr(&self) -> SocketAddr
pub fn local_addr(&self) -> SocketAddr
Returns the local address the server is bound to.
Sourcepub fn handle(&self) -> SoeHandle
pub fn handle(&self) -> SoeHandle
Returns a cloneable handle for sending commands to the server from any task.
Sourcepub async fn recv_event(&mut self) -> Option<SocketEvent<SocketAddr>>
pub async fn recv_event(&mut self) -> Option<SocketEvent<SocketAddr>>
Awaits the next event from the driver loop, or None once the loop has
stopped.