Skip to main content

Server

Struct Server 

Source
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

Source

pub fn new(cfg: ServerConfig) -> Server

a server with these limits and no transport yet (bind_udp, listen_ws, ws_endpoint)

Source

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

Source

pub fn ws_endpoint(&self) -> WsEndpoint

the handle an HTTP handler hands WebSockets in with

Source

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

Source

pub fn udp_addr(&self) -> Option<SocketAddr>

the UDP socket’s address

Source

pub fn ws_addr(&self) -> Option<SocketAddr>

the address of listen_ws’s HTTP server

Source

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

Source

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)

Source

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)

Source

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

Source

pub fn disconnect(&mut self, id: u32)

end a client’s connection (Disconnected(Local) follows)

Source

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)

Source

pub fn public_key(&self) -> Option<[u8; 32]>

the public key of set_static_key, for the clients

Source

pub fn connections(&self) -> usize

connections now

Source

pub fn ids(&self) -> Vec<u32>

the ids of the connections

Source

pub fn stats(&self, id: u32) -> Option<Stats>

a connection’s counts and round-trip time

Source

pub fn peer(&self, id: u32) -> Option<(Transport, Option<SocketAddr>)>

a connection’s transport and address

Source

pub fn server_stats(&self) -> ServerStats

what the server counted beyond its connections

Source

pub fn stop(self)

end every connection, stop the threads and the HTTP server

Trait Implementations§

Source§

impl Drop for Server

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Server

§

impl !Sync for Server

§

impl !UnwindSafe for Server

§

impl Forget for Server

§

impl Freeze for Server
where *const LeafNode<u32, Peer> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(u32, Peer)>>: Freeze, *const LeafNode<SocketAddr, u32> is !null: Freeze, PhantomData<Box<(SocketAddr, u32)>>: Freeze, *const LeafNode<u32, u32> is !null: Freeze, PhantomData<Box<(u32, u32)>>: Freeze, *const LeafNode<u32, (u64, Option<SocketAddr>)> is !null: Freeze, PhantomData<Box<(u32, (u64, Option<SocketAddr>))>>: Freeze, *const u8 is !null: Freeze, PhantomData<ServerEvent>: Freeze, PhantomData<Out>: Freeze, *const LeafNode<[u8; 8], Bucket> is !null: Freeze, PhantomData<Box<([u8; 8], Bucket)>>: Freeze, *const ArcInner<Shared> is !null: Freeze, PhantomData<ArcInner<Shared>>: Freeze, *const ArcInner<Chan<Inbound>> is !null: Freeze, PhantomData<ArcInner<Chan<Inbound>>>: Freeze, *const ArcInner<UdpSocket> is !null: Freeze, PhantomData<ArcInner<UdpSocket>>: Freeze, *const ArcInner<Atomic<bool>> is !null: Freeze, PhantomData<ArcInner<Atomic<bool>>>: Freeze, *mut ThreadRec: Freeze, PhantomData<Thread>: Freeze, *const ArcInner<Mutex<Vec<(Arc<Atomic<bool>>, Thread)>>> is !null: Freeze, PhantomData<ArcInner<Mutex<Vec<(Arc<Atomic<bool>>, Thread)>>>>: Freeze,

§

impl Move for Server

§

impl Send for Server
where NodeRef<Owned, u32, Peer, LeafOrInternal>: Send, BoxRaw<(u32, Peer)>: Send, NodeRef<Owned, SocketAddr, u32, LeafOrInternal>: Send, BoxRaw<(SocketAddr, u32)>: Send, NodeRef<Owned, u32, u32, LeafOrInternal>: Send, BoxRaw<(u32, u32)>: Send, NodeRef<Owned, u32, (u64, Option<SocketAddr>), LeafOrInternal>: Send, BoxRaw<(u32, (u64, Option<SocketAddr>))>: Send, RawVecInner: Send, NodeRef<Owned, [u8; 8], Bucket, LeafOrInternal>: Send, BoxRaw<([u8; 8], Bucket)>: Send, Arc<Shared>: Send, Arc<Chan<Inbound>>: Send, Arc<UdpSocket>: Send, Arc<Atomic<bool>>: Send, Thread: Send, Arc<Mutex<Vec<(Arc<Atomic<bool>>, Thread)>>>: Send,

§

impl Unpin for Server
where *const LeafNode<u32, Peer> is !null: Unpin, Box<(u32, Peer)>: Unpin, *const LeafNode<SocketAddr, u32> is !null: Unpin, Box<(SocketAddr, u32)>: Unpin, *const LeafNode<u32, u32> is !null: Unpin, Box<(u32, u32)>: Unpin, *const LeafNode<u32, (u64, Option<SocketAddr>)> is !null: Unpin, Box<(u32, (u64, Option<SocketAddr>))>: Unpin, *const u8 is !null: Unpin, *const LeafNode<[u8; 8], Bucket> is !null: Unpin, Box<([u8; 8], Bucket)>: Unpin, Arc<Shared>: Unpin, Arc<Chan<Inbound>>: Unpin, Arc<UdpSocket>: Unpin, Arc<Atomic<bool>>: Unpin, *mut ThreadRec: Unpin, Arc<Mutex<Vec<(Arc<Atomic<bool>>, Thread)>>>: Unpin,

§

impl UnsafeUnpin for Server
where *const LeafNode<u32, Peer> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(u32, Peer)>>: UnsafeUnpin, *const LeafNode<SocketAddr, u32> is !null: UnsafeUnpin, PhantomData<Box<(SocketAddr, u32)>>: UnsafeUnpin, *const LeafNode<u32, u32> is !null: UnsafeUnpin, PhantomData<Box<(u32, u32)>>: UnsafeUnpin, *const LeafNode<u32, (u64, Option<SocketAddr>)> is !null: UnsafeUnpin, PhantomData<Box<(u32, (u64, Option<SocketAddr>))>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<ServerEvent>: UnsafeUnpin, PhantomData<Out>: UnsafeUnpin, *const LeafNode<[u8; 8], Bucket> is !null: UnsafeUnpin, PhantomData<Box<([u8; 8], Bucket)>>: UnsafeUnpin, *const ArcInner<Shared> is !null: UnsafeUnpin, PhantomData<ArcInner<Shared>>: UnsafeUnpin, *const ArcInner<Chan<Inbound>> is !null: UnsafeUnpin, PhantomData<ArcInner<Chan<Inbound>>>: UnsafeUnpin, *const ArcInner<UdpSocket> is !null: UnsafeUnpin, PhantomData<ArcInner<UdpSocket>>: UnsafeUnpin, *const ArcInner<Atomic<bool>> is !null: UnsafeUnpin, PhantomData<ArcInner<Atomic<bool>>>: UnsafeUnpin, *mut ThreadRec: UnsafeUnpin, PhantomData<Thread>: UnsafeUnpin, *const ArcInner<Mutex<Vec<(Arc<Atomic<bool>>, Thread)>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Vec<(Arc<Atomic<bool>>, Thread)>>>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.