pub struct Server { /* private fields */ }
Expand description

A server.

Listens on a address and port, allowing for clients to connect. Newly connected clients will be given a client ID (CId) starting at 1 that is unique for the session.

This will manage multiple connections to clients. Each connection will have a TCP and UDP connection on the same address and port.

Implementations

Creates a new Server.

Creates a new Server listening on the address listen_addr.

Gets the config of the server.

Disconnects from the given cid. You should always disconnect all clients before dropping the server to let the clients know that you intentionally disconnected. The discon_msg allows you to give a reason for the disconnect.

Handles all available new connection attempts in a loop, calling the given hook for each.

The hook function should return (should_accept, response_msg).

Types C and R need to match the C and R types that you passed into MsgTable::build().

Returns whether a connection was handled.

Handles all available new connection attempts in a loop, calling the given hook for each.

The hook function should return (should_accept, response_msg).

Types C and R need to match the C and R types that you passed into MsgTable::build().

Returns the number of handled connections.

Handles a single disconnect, if there is one available to handle.

If there is no disconnects to handle, hook will not be called.

Returns weather it handled a disconnect.

Handles all remaining disconnects.

Returns the number of disconnects handled.

Sends a message to the CId cid.

Broadcasts a message to all connected clients.

Sends a message to all CIds that match spec.

Gets an iterator for the messages of type T.

Make sure to call recv_msgs() before calling this.

Panics

Panics if the type T was not registered. For a non-panicking version, see try_recv().

Gets an iterator for the messages of type T.

Make sure to call recv_msgs() before calling this.

Returns None if the type T was not registered.

Gets an iterator for the messages of type T that have been received from CIds that match spec.

Make sure to call recv_msgs()

Panics

Panics if the type T was not registered. For a non-panicking version, see try_recv_spec().

Gets an iterator for the messages of type T that have been received from CIds that match spec.

Make sure to call recv_msgs()

Returns None if the type T was not registered.

Receives the messages from the connections. This should be done before calling recv<T>().

When done in a game loop, you should call clear_msgs(), then recv_msgs() before default time. This will clear the messages between frames.

Clears messages from the buffer.

Gets the address that the server is listening on.

An iterator of the CIds.

Returns whether the connection of the given CId is alive.

Returns whether a message of type tid can be sent.

The number of active connections. To ensure an accurate count, it is best to call this after calling handle_disconnects().

Gets the address of the given CId.

Gets the address of the given CId.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.