pub struct Server { /* private fields */ }Expand description
a game server’s channels (see the top of this file). Dropping it stops it
Implementations§
Source§impl Server
impl Server
Sourcepub fn new(cfg: ServerConfig) -> Server
pub fn new(cfg: ServerConfig) -> Server
a server with these limits and no transport yet (bind_udp, listen_ws, ws_endpoint)
Sourcepub fn bind_udp(&mut self, addr: &SocketAddr) -> NetResult<SocketAddr>
pub fn bind_udp(&mut self, addr: &SocketAddr) -> NetResult<SocketAddr>
listen for UDP clients on addr (port 0: a free one) -> the address it got
Sourcepub fn ws_endpoint(&self) -> WsEndpoint
pub fn ws_endpoint(&self) -> WsEndpoint
the handle an HTTP handler hands WebSockets in with
Sourcepub fn listen_ws(
&mut self,
addr: &SocketAddr,
path: &str,
) -> NetResult<SocketAddr>
pub fn listen_ws( &mut self, addr: &SocketAddr, path: &str, ) -> NetResult<SocketAddr>
a netio HTTP server on addr whose path takes the WebSockets (404 elsewhere) -> its
address
Sourcepub fn udp_addr(&self) -> Option<SocketAddr>
pub fn udp_addr(&self) -> Option<SocketAddr>
the UDP socket’s address
Sourcepub fn ws_addr(&self) -> Option<SocketAddr>
pub fn ws_addr(&self) -> Option<SocketAddr>
the address of listen_ws’s HTTP server
Sourcepub fn wait(&mut self, ms: u32)
pub fn wait(&mut self, ms: u32)
sleep until a datagram or a WebSocket message arrives, at most ms (a server without a
tick of its own; keep ms below keepalive_ms). poll() then reports it
Sourcepub fn poll(&mut self) -> Option<ServerEvent>
pub fn poll(&mut self) -> Option<ServerEvent>
the next event; call it until None every tick (it takes what came, sends keep-alives, ends connections that timed out)
Sourcepub fn send(&mut self, id: u32, payload: &[u8]) -> Result<u16, Error>
pub fn send(&mut self, id: u32, payload: &[u8]) -> Result<u16, Error>
send a message to a client -> its sequence number (Backlog: a WebSocket client has LINK_UNSENT bytes waiting)
Sourcepub fn send_reliable(&mut self, id: u32, payload: &[u8]) -> Result<(), Error>
pub fn send_reliable(&mut self, id: u32, payload: &[u8]) -> Result<(), Error>
send a message on a client’s reliable channel: any size up to ServerConfig::max_message, in order, over UDP sent again until the client has it (endpoint::ServerCore::send_reliable). It goes out at reliable_bytes_per_s, the rest with the next polls
Sourcepub fn disconnect(&mut self, id: u32)
pub fn disconnect(&mut self, id: u32)
end a client’s connection (Disconnected(Local) follows)
Sourcepub fn set_static_key(&mut self, secret: [u8; 32])
pub fn set_static_key(&mut self, secret: [u8; 32])
a long-lived X25519 secret (32 random bytes the app made once and keeps): clients with its public key in ClientConfig::server_key can tell this server from anyone in its place (endpoint::ServerCore::set_static_key)
Sourcepub fn public_key(&self) -> Option<[u8; 32]>
pub fn public_key(&self) -> Option<[u8; 32]>
the public key of set_static_key, for the clients
Sourcepub fn connections(&self) -> usize
pub fn connections(&self) -> usize
connections now
Sourcepub fn peer(&self, id: u32) -> Option<(Transport, Option<SocketAddr>)>
pub fn peer(&self, id: u32) -> Option<(Transport, Option<SocketAddr>)>
a connection’s transport and address
Sourcepub fn server_stats(&self) -> ServerStats
pub fn server_stats(&self) -> ServerStats
what the server counted beyond its connections