Client

Struct Client 

Source
pub struct Client<E: Copy + Eq + Hash + Send + Sync> { /* private fields */ }
Expand description

Client can send/receive messages to/from a server, and has a pool of in-scope entities/components that are synced with the server

Implementations§

Source§

impl<E: Copy + Eq + Hash + Send + Sync> Client<E>

Source

pub fn new<P: Into<Protocol>>(client_config: ClientConfig, protocol: P) -> Self

Create a new Client

Source

pub fn auth<M: Message>(&mut self, auth: M)

Set the auth object to use when setting up a connection with the Server

Source

pub fn auth_headers(&mut self, headers: Vec<(String, String)>)

Source

pub fn connect<S: Into<Box<dyn Socket>>>(&mut self, socket: S)

Connect to the given server address

Source

pub fn connection_status(&self) -> ConnectionStatus

Returns client’s current connection status

Source

pub fn disconnect(&mut self)

Disconnect from Server

Source

pub fn socket_config(&self) -> &SocketConfig

Returns socket config

Source

pub fn receive<W: WorldMutType<E>>(&mut self, world: W) -> Events<E>

Must call this regularly (preferably at the beginning of every draw frame), in a loop until it returns None. Retrieves incoming update data from the server, and maintains the connection.

Source

pub fn send_message<C: Channel, M: Message>(&mut self, message: &M)

Queues up an Message to be sent to the Server

Source

pub fn send_request<C: Channel, Q: Request>( &mut self, request: &Q, ) -> Result<ResponseReceiveKey<Q::Response>, NaiaClientError>

Source

pub fn send_response<S: Response>( &mut self, response_key: &ResponseSendKey<S>, response: &S, ) -> bool

Sends a Response for a given Request. Returns whether or not was successful.

Source

pub fn receive_response<S: Response>( &mut self, response_key: &ResponseReceiveKey<S>, ) -> Option<S>

Source

pub fn send_tick_buffer_message<C: Channel, M: Message>( &mut self, tick: &Tick, message: &M, )

Source

pub fn spawn_entity<W: WorldMutType<E>>( &mut self, world: W, ) -> EntityMut<'_, E, W>

Creates a new Entity and returns an EntityMut which can be used for further operations on the Entity

Source

pub fn entity<W: WorldRefType<E>>( &self, world: W, entity: &E, ) -> EntityRef<'_, E, W>

Retrieves an EntityRef that exposes read-only operations for the given Entity. Panics if the Entity does not exist.

Source

pub fn entity_mut<W: WorldMutType<E>>( &mut self, world: W, entity: &E, ) -> EntityMut<'_, E, W>

Retrieves an EntityMut that exposes read and write operations for the Entity. Panics if the Entity does not exist.

Source

pub fn entities<W: WorldRefType<E>>(&self, world: &W) -> Vec<E>

Return a list of all Entities

Source

pub fn entity_owner(&self, entity: &E) -> EntityOwner

Source

pub fn enable_entity_replication(&mut self, entity: &E)

This is used only for Hecs/Bevy adapter crates, do not use otherwise!

Source

pub fn disable_entity_replication(&mut self, entity: &E)

This is used only for Hecs/Bevy adapter crates, do not use otherwise!

Source

pub fn entity_replication_config(&self, entity: &E) -> Option<ReplicationConfig>

This is used only for Hecs/Bevy adapter crates, do not use otherwise!

Source

pub fn configure_entity_replication<W: WorldMutType<E>>( &mut self, world: &mut W, entity: &E, config: ReplicationConfig, )

This is used only for Hecs/Bevy adapter crates, do not use otherwise!

Source

pub fn entity_authority_status(&self, entity: &E) -> Option<EntityAuthStatus>

This is used only for Hecs/Bevy adapter crates, do not use otherwise!

Source

pub fn entity_request_authority(&mut self, entity: &E)

This is used only for Hecs/Bevy adapter crates, do not use otherwise!

Source

pub fn entity_release_authority(&mut self, entity: &E)

This is used only for Hecs/Bevy adapter crates, do not use otherwise!

Source

pub fn server_address(&self) -> Result<SocketAddr, NaiaClientError>

Get the address currently associated with the Server

Source

pub fn rtt(&self) -> f32

Gets the average Round Trip Time measured to the Server

Source

pub fn jitter(&self) -> f32

Gets the average Jitter measured in connection to the Server

Source

pub fn client_tick(&self) -> Option<Tick>

Gets the current tick of the Client

Source

pub fn client_instant(&self) -> Option<GameInstant>

Gets the current instant of the Client

Source

pub fn server_tick(&self) -> Option<Tick>

Gets the current tick of the Server

Source

pub fn server_instant(&self) -> Option<GameInstant>

Gets the current instant of the Server

Source

pub fn tick_to_instant(&self, tick: Tick) -> Option<GameInstant>

Source

pub fn tick_duration(&self) -> Option<Duration>

Source

pub fn client_interpolation(&self) -> Option<f32>

Gets the interpolation tween amount for the current frame, for use by entities on the Client Tick (i.e. predicted)

Source

pub fn server_interpolation(&self) -> Option<f32>

Gets the interpolation tween amount for the current frame, for use by entities on the Server Tick (i.e. authoritative)

Source

pub fn outgoing_bandwidth(&mut self) -> f32

Source

pub fn incoming_bandwidth(&mut self) -> f32

Source

pub fn despawn_entity_worldless(&mut self, entity: &E)

Source

pub fn insert_component_worldless( &mut self, entity: &E, component: &mut dyn Replicate, )

Source

pub fn remove_component_worldless( &mut self, entity: &E, component_kind: &ComponentKind, )

Source

pub fn add_redundant_remote_entity_to_host( &mut self, world_entity: &E, remote_entity: RemoteEntity, )

Trait Implementations§

Auto Trait Implementations§

§

impl<E> Freeze for Client<E>

§

impl<E> !RefUnwindSafe for Client<E>

§

impl<E> Send for Client<E>

§

impl<E> Sync for Client<E>

§

impl<E> Unpin for Client<E>
where E: Unpin,

§

impl<E> !UnwindSafe for Client<E>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,