[][src]Struct message_io::network::NetworkManager

pub struct NetworkManager { /* fields omitted */ }

NetworkManager allows to manage the network easier. It is in mainly in charge to transform raw data from the network into message events and vice versa.

Implementations

impl<'a> NetworkManager[src]

pub fn new<InMessage, C>(event_callback: C) -> NetworkManager where
    InMessage: for<'b> Deserialize<'b> + Send + 'static,
    C: Fn(NetEvent<InMessage>) + Send + 'static, 
[src]

Creates a new NetworkManager. The user must register an event_callback that can be called each time the network generate and NetEvent

pub fn connect(
    &mut self,
    addr: SocketAddr,
    transport: TransportProtocol
) -> Option<(Endpoint, SocketAddr)>
[src]

Creates a connection to the specific address thougth the given protocol. The endpoint, an identified of the new connection, will be returned among with the local address of that connection. Only for TCP, if the connection can not be performed (the address is not reached) a None will be returned. UDP has no the ability to be aware of this, so always an endpoint will be returned.

pub fn listen(
    &mut self,
    addr: SocketAddr,
    transport: TransportProtocol
) -> Option<(Endpoint, SocketAddr)>
[src]

Open a port to listen messages from either TCP or UDP. If the port can be opened, a endpoint identifying the listener will be returned among with the local address, or a None if not.

pub fn endpoint_local_address(
    &mut self,
    endpoint: Endpoint
) -> Option<SocketAddr>
[src]

Retrieve the local address associated to an endpoint, or None if the endpoint does not exists.

pub fn endpoint_remote_address(
    &mut self,
    endpoint: Endpoint
) -> Option<SocketAddr>
[src]

Retrieve the address associated to an endpoint, or None if the endpoint does not exists or the endpoint is a listener.

pub fn remove_endpoint(&mut self, endpoint: Endpoint) -> Option<()>[src]

Remove the endpoint. Returns None if the endpoint does not exists.

pub fn send<OutMessage>(
    &mut self,
    endpoint: Endpoint,
    message: OutMessage
) -> Option<()> where
    OutMessage: Serialize
[src]

Serialize and send the message thought the connection represented by the given endpoint. Returns None if the endpoint does not exists.

pub fn send_all<'b, OutMessage>(
    &mut self,
    endpoints: impl IntoIterator<Item = &'b Endpoint>,
    message: OutMessage
) -> Result<(), Vec<Endpoint>> where
    OutMessage: Serialize
[src]

Serialize and send the message thought the connections represented by the given endpoints. When there are severals endpoints to send the data. It is better to call this function instead of several calls to send(), because the serialization only is performed one time for all the endpoints. An Err with the unrecognized ids is returned.

Trait Implementations

impl Drop for NetworkManager[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.