[][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_tcp<A: ToSocketAddrs>(&mut self, addr: A) -> Result<Endpoint>[src]

Creates a connection to the specific address by TCP. The endpoint, an identified of the new connection, will be returned. If the connection can not be performed (e.g. the address is not reached) an error is returned.

pub fn connect_udp<A: ToSocketAddrs>(&mut self, addr: A) -> Result<Endpoint>[src]

Creates a connection to the specific address by UDP. The endpoint, an identified of the new connection, will be returned. If there is an error during the socket creation, an error will be returned.

pub fn listen_tcp<A: ToSocketAddrs>(
    &mut self,
    addr: A
) -> Result<(usize, SocketAddr)>
[src]

Open a port to listen messages from TCP. If the port can be opened, an endpoint identifying the listener is returned along with the local address, or an error if not.

pub fn listen_udp<A: ToSocketAddrs>(
    &mut self,
    addr: A
) -> Result<(usize, SocketAddr)>
[src]

Open a port to listen messages from UDP. If the port can be opened, an endpoint identifying the listener is returned along with the local address, or an error if not.

pub fn listen_udp_multicast<A: ToSocketAddrs>(
    &mut self,
    addr: A
) -> Result<(usize, SocketAddr)>
[src]

Open a port to listen messages from UDP in multicast. If the port can be opened, an endpoint identifying the listener is returned along with the local address, or an error if not. Only ipv4 addresses are allowed.

pub fn remove_resource(&mut self, resource_id: usize) -> Option<()>[src]

Remove a network resource. Returns None if the resource id not exists. This is used mainly to remove resources that the program has been created explicitely, as connection or listeners. Resources of endpoints generated by a TcpListener can also be removed to close the connection. Note: Udp endpoints generated by a UdpListener shared the resource, the own UdpListener. This means that there is no resource to remove as the TCP case.

pub fn local_address(&self, resource_id: usize) -> Option<SocketAddr>[src]

Request a local address of a resource. Returns None if the endpoint id not exists. Note: Udp endpoints generated by a UdpListener shared the resource.

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

Serialize and send the message thought the connection represented by the given endpoint. If the same message should be sent to different endpoints, use send_all() to better performance. Returns an error if there is an error while sending the message, the endpoint does not exists, or if it is not valid.

pub fn send_all<'b, OutMessage>(
    &mut self,
    endpoints: impl IntoIterator<Item = &'b Endpoint>,
    message: OutMessage
) -> Result<(), Vec<(Endpoint, Error)>> 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, this function is faster than consecutive calls to send() since the serialization is only performed one time for all endpoints. An list of erroneous endpoints along their errors is returned if there was a problem with some message sent.

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.