pub struct ClientConfig<Ctx> { /* private fields */ }
Expand description
Configuration for a client.
num_disconnect_packets
- The number of redundant disconnect packets that will be sent to a server when the clients wants to disconnect.packet_send_rate
- The rate at which periodic packets will be sent to the server.on_state_change
- A callback that will be called when the client changes states.
§Example
use netcode::{Client, ClientConfig, ClientState};
let cfg = ClientConfig::with_context(MyContext {})
.num_disconnect_packets(10)
.packet_send_rate(0.1)
.on_state_change(|from, to, _ctx| {
if let (ClientState::SendingChallengeResponse, ClientState::Connected) = (from, to) {
println!("client connected to server");
}
});
let mut client = Client::with_config(&token_bytes, cfg).unwrap();
client.connect();
Implementations§
Source§impl<Ctx> ClientConfig<Ctx>
impl<Ctx> ClientConfig<Ctx>
Sourcepub fn new() -> ClientConfig<()>
pub fn new() -> ClientConfig<()>
Create a new, default client configuration with no context.
Sourcepub fn with_context(ctx: Ctx) -> Self
pub fn with_context(ctx: Ctx) -> Self
Create a new client configuration with context that will be passed to the callbacks.
Sourcepub fn num_disconnect_packets(self, num_disconnect_packets: usize) -> Self
pub fn num_disconnect_packets(self, num_disconnect_packets: usize) -> Self
Set the number of redundant disconnect packets that will be sent to a server when the clients wants to disconnect. The default is 10 packets.
Sourcepub fn packet_send_rate(self, rate_seconds: f64) -> Self
pub fn packet_send_rate(self, rate_seconds: f64) -> Self
Set the rate at which periodic packets will be sent to the server.
The default is 10 packets per second. (0.1
seconds)
Sourcepub fn on_state_change<F>(self, cb: F) -> Self
pub fn on_state_change<F>(self, cb: F) -> Self
Set a callback that will be called when the client changes states.
Trait Implementations§
Auto Trait Implementations§
impl<Ctx> Freeze for ClientConfig<Ctx>where
Ctx: Freeze,
impl<Ctx> !RefUnwindSafe for ClientConfig<Ctx>
impl<Ctx> Send for ClientConfig<Ctx>where
Ctx: Send,
impl<Ctx> Sync for ClientConfig<Ctx>where
Ctx: Sync,
impl<Ctx> Unpin for ClientConfig<Ctx>where
Ctx: Unpin,
impl<Ctx> !UnwindSafe for ClientConfig<Ctx>
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
Mutably borrows from an owned value. Read more