Struct renetcode::NetcodeClient
source · [−]pub struct NetcodeClient { /* private fields */ }
Expand description
A client that can generate encrypted packets that be sent to the connected server, or consume encrypted packets from the server. The client is agnostic from the transport layer, only consuming and generating bytes that can be transported in any way desired.
Implementations
sourceimpl NetcodeClient
impl NetcodeClient
pub fn new(
current_time: Duration,
client_id: u64,
connect_token: ConnectToken
) -> Self
pub fn connected(&self) -> bool
pub fn client_id(&self) -> u64
sourcepub fn disconnected(&self) -> Option<DisconnectReason>
pub fn disconnected(&self) -> Option<DisconnectReason>
Returns the reason that the client was disconnected for.
sourcepub fn server_addr(&self) -> SocketAddr
pub fn server_addr(&self) -> SocketAddr
Returns the current server address the client is connected or trying to connect.
sourcepub fn disconnect(&mut self) -> Result<PacketToSend<'_>, NetcodeError>
pub fn disconnect(&mut self) -> Result<PacketToSend<'_>, NetcodeError>
Disconnect the client from the server. Returns a disconnect packet that should be sent to the server.
sourcepub fn process_packet<'a>(&mut self, buffer: &'a mut [u8]) -> Option<&'a [u8]>
pub fn process_packet<'a>(&mut self, buffer: &'a mut [u8]) -> Option<&'a [u8]>
Process any packet received from the server. This function might return a payload sent from the server. If nothing is returned, it was a packet used for the internal protocol or an invalid packet.
sourcepub fn generate_payload_packet(
&mut self,
payload: &[u8]
) -> Result<PacketToSend<'_>, NetcodeError>
pub fn generate_payload_packet(
&mut self,
payload: &[u8]
) -> Result<PacketToSend<'_>, NetcodeError>
Returns the server address and an encrypted payload packet that can be sent to the server.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for NetcodeClient
impl Send for NetcodeClient
impl Sync for NetcodeClient
impl Unpin for NetcodeClient
impl UnwindSafe for NetcodeClient
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more