[][src]Struct message_io::network::Network

pub struct Network { /* fields omitted */ }

Network 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> Network[src]

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

Creates a new Network. 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 resource id 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 resource id 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 resource id 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) 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. The funcion panics if some of endpoints do not exists. If the endpoint disconnects during the sending, a RemoveEndpoint is generated.

pub fn send_all<'b, OutMessage>(
    &mut self,
    endpoints: impl IntoIterator<Item = &'b Endpoint>,
    message: OutMessage
) 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. The funcion panics if some of endpoints do not exists. If the protocol is UDP, the function panics if the message size is higher than MTU. If the endpoint disconnects during the sending, a RemoveEndpoint is generated.

Trait Implementations

impl Drop for Network[src]

Auto Trait Implementations

impl !RefUnwindSafe for Network

impl Send for Network

impl Sync for Network

impl Unpin for Network

impl !UnwindSafe for Network

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.