✨ bevy_stardust

Stardust is a batteries-included networking crate built for Bevy. Stardust intends to make networking easy, but lets you do the hard stuff when you want to.

License badge Bevy version badge

Features

Note: While you can use any transport layer, Stardust by itself only supports native UDP.

Planned features

Usage

This applies to the UDP transport layer.

```rs // In a shared location

use bevy::prelude::; use bevy_stardust::shared::prelude::;

[derive(Debug, Reflect)]

struct MyChannel; rs // On the client

use bevy::prelude::; use bevy_stardust::client::prelude::;

fn main() { let mut app = App::new(); app.addplugins(StardustClientPlugin); app.addplugins(ClientUdpTransportPlugin);

app.register_channel::<MyChannel>(ChannelConfig {
    direction: ChannelDirection::Bidirectional,
}, ());

app.add_systems(WriteOctetStrings, sender_system);

}

fn sender_system( connection: Res>, mut writer: ChannelWriter, ) { if !connection.connected() { return; }

writer.send("Hello, world!".into_bytes()).unwrap();

} rs // On the server

use bevy::prelude::; use bevy_stardust::server::prelude::;

fn main() { let mut app = App::new(); app.addplugins(StardustServerPlugin); app.addplugins(ServerUdpTransportPlugin { address: IpAddr::V4(Ipv4Addr::UNSPECIFIED), listenport: 12345, activeports: 12346..=12356, })

app.register_channel::<MyChannel>(ChannelConfig {
    direction: ChannelDirection::Bidirectional,
}, ());

app.insert_resource(NetworkClientCap(64));

app.add_systems(ReadOctetStrings, receiver_system);

}

fn receiversystem( reader: ChannelReader, ) { for (client, messages) in reader.readall() { for message in messages.0.iter() { let string = String::fromutf8lossy(message.read()); println!("{:?} said {:?}", client, &string); } } } ```