pub struct RenetServer { /* private fields */ }Implementations§
Source§impl RenetServer
impl RenetServer
pub fn new(connection_config: ConnectionConfig) -> Self
Sourcepub fn add_connection(&mut self, client_id: ClientId, socket_is_reliable: bool)
pub fn add_connection(&mut self, client_id: ClientId, socket_is_reliable: bool)
Adds a new connection to the server. If a connection already exits it does nothing.
The argument socket_is_reliable should be set if using something like WebSockets for the underlying
connection. The client should also set that value in their RenetClient.
Note: This should only be called by the transport layer.
Sourcepub fn get_event(&mut self) -> Option<ServerEvent>
pub fn get_event(&mut self) -> Option<ServerEvent>
Returns a server event if available
§Usage
while let Some(event) = server.get_event() {
match event {
ServerEvent::ClientConnected { client_id } => {
println!("Client {client_id} connected.")
}
ServerEvent::ClientDisconnected { client_id, reason } => {
println!("Client {client_id} disconnected: {reason}");
}
}
}Sourcepub fn has_connections(&self) -> bool
pub fn has_connections(&self) -> bool
Returns whether or not the server has connections
Sourcepub fn disconnect_reason(&self, client_id: ClientId) -> Option<DisconnectReason>
pub fn disconnect_reason(&self, client_id: ClientId) -> Option<DisconnectReason>
Returns the disconnection reason for the client if its disconnected
Sourcepub fn rtt(&self, client_id: ClientId) -> f64
pub fn rtt(&self, client_id: ClientId) -> f64
Returns the round-time trip for the client or 0.0 if the client is not found
Sourcepub fn packet_loss(&self, client_id: ClientId) -> f64
pub fn packet_loss(&self, client_id: ClientId) -> f64
Returns the packet loss for the client or 0.0 if the client is not found
Sourcepub fn bytes_sent_per_sec(&self, client_id: ClientId) -> f64
pub fn bytes_sent_per_sec(&self, client_id: ClientId) -> f64
Returns the bytes sent per seconds for the client or 0.0 if the client is not found
Sourcepub fn bytes_received_per_sec(&self, client_id: ClientId) -> f64
pub fn bytes_received_per_sec(&self, client_id: ClientId) -> f64
Returns the bytes received per seconds for the client or 0.0 if the client is not found
Sourcepub fn network_info(
&self,
client_id: ClientId,
) -> Result<NetworkInfo, ClientNotFound>
pub fn network_info( &self, client_id: ClientId, ) -> Result<NetworkInfo, ClientNotFound>
Returns all network informations for the client
Sourcepub fn remove_connection(&mut self, client_id: ClientId)
pub fn remove_connection(&mut self, client_id: ClientId)
Removes a connection from the server, emits an disconnect server event. It does nothing if the client does not exits.
Note: This should only be called by the transport layer.
Sourcepub fn disconnect(&mut self, client_id: ClientId)
pub fn disconnect(&mut self, client_id: ClientId)
Disconnects a client, it does nothing if the client does not exist.
Sourcepub fn disconnect_all(&mut self)
pub fn disconnect_all(&mut self)
Disconnects all client.
Sourcepub fn broadcast_message<I: Into<u8>, B: Into<Bytes>>(
&mut self,
channel_id: I,
message: B,
)
pub fn broadcast_message<I: Into<u8>, B: Into<Bytes>>( &mut self, channel_id: I, message: B, )
Send a message to all clients over a channel.
Sourcepub fn broadcast_message_except<I: Into<u8>, B: Into<Bytes>>(
&mut self,
except_id: ClientId,
channel_id: I,
message: B,
)
pub fn broadcast_message_except<I: Into<u8>, B: Into<Bytes>>( &mut self, except_id: ClientId, channel_id: I, message: B, )
Send a message to all clients, except the specified one, over a channel.
Sourcepub fn channel_available_memory<I: Into<u8>>(
&self,
client_id: ClientId,
channel_id: I,
) -> usize
pub fn channel_available_memory<I: Into<u8>>( &self, client_id: ClientId, channel_id: I, ) -> usize
Returns the available memory in bytes of a channel for the given client. Returns 0 if the client is not found.
Sourcepub fn can_send_message<I: Into<u8>>(
&self,
client_id: ClientId,
channel_id: I,
size_bytes: usize,
) -> bool
pub fn can_send_message<I: Into<u8>>( &self, client_id: ClientId, channel_id: I, size_bytes: usize, ) -> bool
Checks if can send a message with the given size in bytes over a channel for the given client. Returns false if the client is not found.
Sourcepub fn send_message<I: Into<u8>, B: Into<Bytes>>(
&mut self,
client_id: ClientId,
channel_id: I,
message: B,
)
pub fn send_message<I: Into<u8>, B: Into<Bytes>>( &mut self, client_id: ClientId, channel_id: I, message: B, )
Send a message to a client over a channel.
Sourcepub fn receive_message<I: Into<u8>>(
&mut self,
client_id: ClientId,
channel_id: I,
) -> Option<Bytes>
pub fn receive_message<I: Into<u8>>( &mut self, client_id: ClientId, channel_id: I, ) -> Option<Bytes>
Receive a message from a client over a channel.
Sourcepub fn clients_id_iter(&self) -> impl Iterator<Item = ClientId> + '_
pub fn clients_id_iter(&self) -> impl Iterator<Item = ClientId> + '_
Return ids for all connected clients (iterator)
Sourcepub fn clients_id(&self) -> Vec<ClientId>
pub fn clients_id(&self) -> Vec<ClientId>
Return ids for all connected clients
Sourcepub fn disconnections_id_iter(&self) -> impl Iterator<Item = ClientId> + '_
pub fn disconnections_id_iter(&self) -> impl Iterator<Item = ClientId> + '_
Return ids for all disconnected clients (iterator)
Sourcepub fn disconnections_id(&self) -> Vec<ClientId>
pub fn disconnections_id(&self) -> Vec<ClientId>
Return ids for all disconnected clients
Sourcepub fn connected_clients(&self) -> usize
pub fn connected_clients(&self) -> usize
Returns the current number of connected clients.
pub fn is_connected(&self, client_id: ClientId) -> bool
Sourcepub fn update(&mut self, duration: Duration)
pub fn update(&mut self, duration: Duration)
Advances the server by the duration. Should be called every tick
Sourcepub fn get_packets_to_send(
&mut self,
client_id: ClientId,
) -> Result<Vec<Payload>, ClientNotFound>
pub fn get_packets_to_send( &mut self, client_id: ClientId, ) -> Result<Vec<Payload>, ClientNotFound>
Returns a list of packets to be sent to the client.
Note: This should only be called by the transport layer.
Sourcepub fn process_packet_from(
&mut self,
payload: &[u8],
client_id: ClientId,
) -> Result<(), ClientNotFound>
pub fn process_packet_from( &mut self, payload: &[u8], client_id: ClientId, ) -> Result<(), ClientNotFound>
Process a packet received from the client.
Note: This should only be called by the transport layer.
Sourcepub fn new_local_client(&mut self, client_id: ClientId) -> RenetClient
pub fn new_local_client(&mut self, client_id: ClientId) -> RenetClient
Creates a local RenetClient, use this for testing.
Use Self::process_local_client to update the local connection.
Sourcepub fn disconnect_local_client(
&mut self,
client_id: ClientId,
client: &mut RenetClient,
)
pub fn disconnect_local_client( &mut self, client_id: ClientId, client: &mut RenetClient, )
Disconnects a local RenetClient that was created with Self::new_local_client.
Sourcepub fn process_local_client(
&mut self,
client_id: ClientId,
client: &mut RenetClient,
) -> Result<(), ClientNotFound>
pub fn process_local_client( &mut self, client_id: ClientId, client: &mut RenetClient, ) -> Result<(), ClientNotFound>
Given a local RenetClient, receive and send packets to/from it.
Use this to update local client created from Self::new_local_client.
Trait Implementations§
Source§impl Debug for RenetServer
impl Debug for RenetServer
impl Resource for RenetServer
Auto Trait Implementations§
impl Freeze for RenetServer
impl RefUnwindSafe for RenetServer
impl Send for RenetServer
impl Sync for RenetServer
impl Unpin for RenetServer
impl UnwindSafe for RenetServer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.