pub enum NetEvent<'a> {
Connected(Endpoint, bool),
Accepted(Endpoint, ResourceId),
Message(Endpoint, &'a [u8]),
Disconnected(Endpoint),
}
Expand description
Enum used to describe a network event that an internal transport adapter has produced.
Variants§
Connected(Endpoint, bool)
Connection result.
This event is only generated after a crate::network::NetworkController::connect()
call.
The event contains the endpoint of the connection
(same endpoint returned by the connect()
method),
and a boolean indicating the result of that connection.
In non connection-oriented transports as UDP it simply means that the resource
is ready to use, and the boolean will be always true
.
In connection-oriented transports it means that the handshake has been performed, and the
connection is established and ready to use.
Since this handshake could fail, the boolean could be false
.
Accepted(Endpoint, ResourceId)
New endpoint has been accepted by a listener and considered ready to use. The event contains the resource id of the listener that accepted this connection.
Note that this event will only be generated by connection-oriented transports as TCP.
Message(Endpoint, &'a [u8])
Input message received by the network. In packet-based transports, the data of a message sent corresponds with the data of this event. This one-to-one relation is not conserved in stream-based transports as TCP.
If you want a packet-based protocol over TCP use
crate::network::Transport::FramedTcp
.
Disconnected(Endpoint)
This event is only dispatched when a connection is lost.
Remove explicitely a resource will NOT generate the event.
When this event is received, the resource is considered already removed,
the user do not need to remove it after this event.
A NetEvent::Message
event will never be generated after this event from this endpoint.
Note that this event will only be generated by connection-oriented transports as TCP. UDP, for example, is NOT connection-oriented, and the event can no be detected.