Struct carrier_pigeon::Client
source · [−]pub struct Client { /* private fields */ }
Expand description
A Client connection.
This can only connect to 1 server.
Contains a TCP and UDP connection to the server.
Implementations
sourceimpl Client
impl Client
sourcepub fn new<C: Any + Send + Sync>(
peer: SocketAddr,
parts: MsgTableParts,
config: Config,
con_msg: C
) -> PendingClient
pub fn new<C: Any + Send + Sync>(
peer: SocketAddr,
parts: MsgTableParts,
config: Config,
con_msg: C
) -> PendingClient
Creates a new Client
.
Creates a new Client
on another thread, passing back a PendingClient
.
This PendingClient
allows you to wait for the client to send the connection
message, and for the server to send back the response message.
sourcepub fn disconnect<D: Any + Send + Sync>(&mut self, discon_msg: &D) -> Result<()>
pub fn disconnect<D: Any + Send + Sync>(&mut self, discon_msg: &D) -> Result<()>
Disconnects from the server. You should call this
method before dropping the client to let the server know that
you intentionally disconnected. The discon_msg
allows you to
give a reason for the disconnect.
sourcepub fn send<T: Any + Send + Sync>(&self, msg: &T) -> Result<()>
pub fn send<T: Any + Send + Sync>(&self, msg: &T) -> Result<()>
Sends a message to the peer.
T
must be registered in the [MsgTable
].
sourcepub fn recv<T: Any + Send + Sync>(
&self
) -> impl Iterator<Item = NetMsg<'_, T>> + '_
pub fn recv<T: Any + Send + Sync>(
&self
) -> impl Iterator<Item = NetMsg<'_, T>> + '_
Gets an iterator for the messages of type T
.
Panics
Panics if the type T
was not registered.
For a non-panicking version, see try_recv().
sourcepub fn try_recv<T: Any + Send + Sync>(
&self
) -> Option<impl Iterator<Item = NetMsg<'_, T>> + '_>
pub fn try_recv<T: Any + Send + Sync>(
&self
) -> Option<impl Iterator<Item = NetMsg<'_, T>> + '_>
Gets an iterator for the messages of type T
.
Returns None
if the type T
was not registered.
sourcepub fn recv_msgs(&mut self) -> u32
pub fn recv_msgs(&mut self) -> u32
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.
sourcepub fn clear_msgs(&mut self)
pub fn clear_msgs(&mut self)
Clears messages from the buffer.
sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Gets the local address.
sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
Gets the address of the peer.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
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