[][src]Struct amethyst_network::NetConnection

pub struct NetConnection<E: 'static> {
    pub target_addr: SocketAddr,
    pub state: ConnectionState,
    // some fields omitted
}

A remote connection to some endpoint.

This type is a Component, and it is used by systems too:

  • Queue received data into this type
  • Read the queued data from the user for transmission.

Remark

Note that this type does not perform any reading or writing, this is done only within systems. This type acts as a container for to send and received data.

Fields

target_addr: SocketAddr

The target remote socket address who is listening for incoming packets.

state: ConnectionState

The state of the connection.

Methods

impl<E: Send + Sync + 'static> NetConnection<E>[src]

pub fn new(target_addr: SocketAddr) -> Self[src]

Construct a new NetConnection.

  • SocketAddr: the remote endpoint, from here the data will be send to and received from.

pub fn queue_iter<I>(&mut self, iter: I) where
    I: IntoIterator<Item = NetEvent<E>>,
    I::IntoIter: ExactSizeIterator
[src]

Queues the given event iterator of events for transmission. This function writes the passed event iterator to a buffer which can be read by a System. It is the job of the System to send those events to the remote client.

pub fn queue_vec(&mut self, events: &mut Vec<NetEvent<E>>)[src]

Queues the given vector of events for transmission. This function writes the passed event vector to a buffer which can be read by a System. It is the job of the System to send those events to the remote client.

pub fn queue(&mut self, event: NetEvent<E>)[src]

Queues a single event for transmission. This function writes the passed event to a buffer which can be read by a System. It is the job of the System to send this event to the remote client.

pub fn received_events(
    &self,
    reader_id: &mut ReaderId<NetEvent<E>>
) -> EventIterator<NetEvent<E>>
[src]

Returns an iterator over the received events.

  • reader_id: the reader id of the registered reader.

Remark

  • To be able to read events, a reader id is required. This is required for the underlying ringbuffer. The reader id stores information of where in the ringbuffer the reader has read from earlier. Please checkout register_reader which will return a ReaderId that allows you to read the received events.

pub fn register_reader(&mut self) -> ReaderId<NetEvent<E>>[src]

Returns a ReaderId that can be used to read from the received events.

Remark

  • To be able to read events, a reader id is required. This is because otherwise the channel wouldn't know where in the ringbuffer the reader has read to earlier. This information is stored in the reader id.

Trait Implementations

impl<E: PartialEq> Eq for NetConnection<E>[src]

impl<E> PartialEq<NetConnection<E>> for NetConnection<E>[src]

impl<E: 'static> Serialize for NetConnection<E>[src]

impl<E: Send + Sync + 'static> Component for NetConnection<E>[src]

type Storage = VecStorage<Self>

Associated storage type for this component.

Auto Trait Implementations

impl<E> Send for NetConnection<E> where
    E: Send + Sync

impl<E> Sync for NetConnection<E> where
    E: Sync

impl<E> Unpin for NetConnection<E> where
    E: Unpin

impl<E> !UnwindSafe for NetConnection<E>

impl<E> !RefUnwindSafe for NetConnection<E>

Blanket Implementations

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.

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

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

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

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<T> Any for T where
    T: Any

impl<T> Resource for T where
    T: Any + Send + Sync
[src]

impl<T> Event for T where
    T: Send + Sync + 'static, 
[src]