Crates.io | bevy_prototype_networking_laminar |
lib.rs | bevy_prototype_networking_laminar |
version | 0.1.0 |
source | src |
created_at | 2020-08-24 03:52:53.076339 |
updated_at | 2020-08-24 03:52:53.076339 |
description | This is a prototype of a networking crate for bevy. This create provides a low-level networking plugin built on top of laminar. |
homepage | https://github.com/ncallaway/bevy_prototype_networking_laminar |
repository | https://github.com/ncallaway/bevy_prototype_networking_laminar |
max_upload_size | |
id | 279990 |
size | 121,081 |
Warning: This is a prototype and not ready for production use
This is a prototype of a networking crate for bevy
. This create provides a low-level networking plugin built on top of laminar
, which adds some simple reliability, ordering, and virtual connection options on top of a UDP socket.
bevy_prototype_networking_laminar
to Cargo.toml
[dependencies]
bevy = "0.1.3"
bevy_prototype_networking_laminar = { git = "https://github.com/ncallaway/bevy_prototype_networking_laminar" }
bevy
app setupuse bevy_prototype_networking_laminar::NetworkingPlugin;
...
app
.add_default_plugins()
> .add_plugin(NetworkingPlugin)
.add_system(...)
fn startup_system(net: ResMut<NetworkResource>) {
net.bind("127.0.0.1:12350").unwrap();
}
fn greeting_system(net: Res<NetworkResource>) {
net.broadcast(b"How is everybody?", NetworkDelivery::ReliableSequenced(Some(1)));
}
NetworkEvent
s to receive incoming messages#[derive(Default)]
struct NetworkListenerState {
network_events: EventReader<NetworkEvent>,
}
App::build()
.add_default_plugins()
.add_plugin(NetworkingPlugin)
> .init_resource::<NetworkListenerState>()
> .add_system(print_network_events.system())
.run();
fn print_network_events(
mut state: ResMut<NetworkListenerState>,
network_events: Res<Events<NetworkEvent>>,
) {
for event in state.network_events.iter(&network_events) {
println!("Received a NetworkEvent: {:?}", event);
}
}
The testbed is a simple project that provides a more comprehensive example of using bevy_prototype_networking_laminar
.
The testbed is also is intended to serve as a testbed for any other networking prototypes or attempts. All interaction with bevy_prototype_networking_laminar
is contained to examples/testbed/net/prototype.rs
. Using the testbed with a different networking plugin should be as simple as updating prototype.rs
to interact with the other networking plugin. Contributions to the testbed to improve the code quality, or make the testbed more comprehensive by adding other prototypical network interactions are welcome.
cargo run --example testbed -- -s 127.0.0.1:12540
to start a servercargo run --example testbed -- -c 127.0.0.1:12541 127.0.0.1:12540 foo
to start a client named foo
connecting to the serverWhen on the server, you:
WASD
MESSAGES
listWhen on the client, you:
MESSAGES
listMESSAGES
list is syncrhonized with the server.The simple example shows a very bare bones bevy
application that will send messages back and forth.
cargo run --example simple -- -s
start a servercargo run --example simple -- -c
start a clientNetwork Event: Message(Connection { addr: V4(127.0.0.1:12351), socket: SocketHandle { identifier: 0 } }, b"How are things over there?")
Network Event: Connected(Connection { addr: V4(127.0.0.1:12351), socket: SocketHandle { identifier: 0 } })
Network Event: Disconnected(Connection { addr: V4(127.0.0.1:12351), socket: SocketHandle { identifier: 0 } })
Network Event: Message(Connection { addr: V4(127.0.0.1:12351), socket: SocketHandle { identifier: 0 } }, b"How are things over there?")
Network Event: Connected(Connection { addr: V4(127.0.0.1:12351), socket: SocketHandle { identifier: 0 } })
Network Event: Disconnected(Connection { addr: V4(127.0.0.1:12351), socket: SocketHandle { identifier: 0 } })
The current prototype implementation is extremely rough and early. The current work is mostly about exploring to discover a Network Plugin API that fits the bevy design. Listed here is the current low-hanging fruit for improving this prototype:
.unwrap()
, .expect()
, .panic()
or silently being dropped. The error handling should be cleaned up throughout the plugin, with a clean presentation of errors to the caller.net/mod.rs
and net/prototype.rs
. Consider cleaning up this interface to make it cleaner to implement a plugin integrationMessage
is unreasonably burdensom. Rename these to something that doesn't have a networking connotation.Reliable
channel, and the Client can request the full list of messages when they connect, or need to reset their state.amethyst-network
exposes a network simulation time
, which helps synchornize time and track frame lag
when sending network messages over the system. Explore this concept, and other common networking tasks that would be useful in a low-level networking plugin.Licesened under the MIT license.