bevy_server_browser

Bevy game engine plugin for creating and searching discoverable servers on local networks.
This plugin does not provide any connection between server and clients, you need to pair it with network library, for example bevy_matchbox. This plugin only allows clients to discover servers and its info on local network, so you do not have to type ip addresses of servers into clients.
Usage
See usage below or examples for more comprehensive usage.
This example shows both server and client in one single app, meaning the client will discover itself, you can use both functionalities or just client or server.
use bevy::{log::LogPlugin, prelude::*};
use bevy_server_browser::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(ServerBrowserPlugin::new("test_id"))
.add_systems(
Startup,
(setup_discoverable_server, discover_servers).chain(),
)
.add_systems(
Update,
print_discovered_servers.run_if(resource_changed::<DiscoveredServerList>()),
)
.run();
}
fn setup_discoverable_server(mut commands: Commands) {
info!("Adding discoverable server");
commands.insert_resource(DiscoverableServer {
name: "Test Server".to_string(),
port: 1234,
});
}
fn discover_servers(mut search_servers: EventWriter<SearchServers>) {
search_servers.send_default();
}
fn print_discovered_servers(servers: Res<DiscoveredServerList>) {
if servers.is_empty() {
info!("No servers discovered");
return;
}
info!("Discovered {} servers:", servers.len());
for server in &servers {
info!(
"Name '{}' ({}) with addresses {:?} on port {}",
server.name, server.hostname, server.addresses, server.port
);
}
}
bevy |
bevy_server_browser |
0.12 |
0.1.0 |