Trait crystalorb::network_resource::NetworkResource [−][src]
pub trait NetworkResource<WorldType: World> {
type ConnectionType: Connection<WorldType>;
fn connections<'a>(
&'a mut self
) -> Box<dyn Iterator<Item = (ConnectionHandleType, Self::ConnectionType)> + 'a>;
fn get_connection(
&mut self,
handle: ConnectionHandleType
) -> Option<Self::ConnectionType>;
fn broadcast_message<MessageType>(&mut self, message: MessageType)
where
MessageType: Debug + Clone + Serialize + DeserializeOwned + Send + Sync + 'static,
{ ... }
fn send_message<MessageType>(
&mut self,
handle: ConnectionHandleType,
message: MessageType
) -> Result<Option<MessageType>, Box<dyn Error + Send>>
where
MessageType: Debug + Clone + Serialize + DeserializeOwned + Send + Sync + 'static,
{ ... }
}
Expand description
CrystalOrb needs an external networking library before it can be used. Such networking library will be responsible for sending three kinds of messages:
ClockSyncMessage
Timestamped<SnapshotType>
(seeTimestamped
andSnapshotType
).Timestamped<CommandType>
(seeTimestamped
andCommandType
).
In theory, the external networking library would not be responsible for understanding these messages. It would only be responsible for sending and receiving them.
How these message channels get multiplexed is up to you / the external networking library.
Whether or not these message channels are reliable or unreliable, ordered or unordered, is also
up to you / the external networking library. CrystalOrb is written assuming that
ClockSyncMessage
and SnapshotType
are unreliable and unordered, while CommandType
is
reliable but unordered.
This interface is based off on the interface provided by the
bevy_networking_turbulence
plugin. See
crystalorb-bevy-networking-turbulence
for an example for integrating with bevy_networking_turbulence
.
Associated Types
type ConnectionType: Connection<WorldType>
type ConnectionType: Connection<WorldType>
The Connection
structure that CrystalOrb will use to send/receive messages from a
specific remote machine. This may probably be a wrapper to a mutable reference to some
connection type that is used by your external networking library of choice, in which
case a generic lifetime parameter is provided here that you can use.
Required methods
fn connections<'a>(
&'a mut self
) -> Box<dyn Iterator<Item = (ConnectionHandleType, Self::ConnectionType)> + 'a>
fn connections<'a>(
&'a mut self
) -> Box<dyn Iterator<Item = (ConnectionHandleType, Self::ConnectionType)> + 'a>
Iterate through the available connections. For servers, this would be the list of current client connections that are still alive. For the client, this would only contain the connection to the server once the connection has been established.
fn get_connection(
&mut self,
handle: ConnectionHandleType
) -> Option<Self::ConnectionType>
fn get_connection(
&mut self,
handle: ConnectionHandleType
) -> Option<Self::ConnectionType>
Get a specific connection given its connection handle.
Provided methods
fn broadcast_message<MessageType>(&mut self, message: MessageType) where
MessageType: Debug + Clone + Serialize + DeserializeOwned + Send + Sync + 'static,
fn broadcast_message<MessageType>(&mut self, message: MessageType) where
MessageType: Debug + Clone + Serialize + DeserializeOwned + Send + Sync + 'static,
Optional: Send the given message to all active connections. A default implementation is
already given that uses NetworkResource::connections
and Connection::send
.
CrystalOrb will invoke this method with the three message types as specified in
NetworkResource
.
fn send_message<MessageType>(
&mut self,
handle: ConnectionHandleType,
message: MessageType
) -> Result<Option<MessageType>, Box<dyn Error + Send>> where
MessageType: Debug + Clone + Serialize + DeserializeOwned + Send + Sync + 'static,
fn send_message<MessageType>(
&mut self,
handle: ConnectionHandleType,
message: MessageType
) -> Result<Option<MessageType>, Box<dyn Error + Send>> where
MessageType: Debug + Clone + Serialize + DeserializeOwned + Send + Sync + 'static,
Optional: Send the given message to the given connection. A default implementation is
already given that uses NetworkResource::get_connection
and Connection::send
.
CrystalOrb will invoke this method with the three message types as specified in
NetworkResource
.
Errors
Returns NotFound
std::io::Error
if a connection with
the given handle
could not be found.