use bevy::prelude::*; use bevy_prototype_networking_laminar::{ NetworkDelivery, NetworkEvent, NetworkResource, NetworkingPlugin, }; use std::net::SocketAddr; const SERVER: &str = "127.0.0.1:12351"; const CLIENT: &str = "127.0.0.1:12350"; fn main() { // // EXAMPLE: using the prototype plugin App::build() .init_resource::() .init_resource::() .add_resource(parse_args()) .add_default_plugins() .add_plugin(NetworkingPlugin) .add_startup_system(startup_system.system()) .add_system(print_network_events.system()) .add_system(send_messages.system()) .run(); } #[derive(Default)] struct EventListenerState { network_events: EventReader, } fn print_network_events( mut state: ResMut, my_events: Res>, ) { for event in state.network_events.iter(&my_events) { println!("Network Event: {:?}", event); } } fn startup_system(net: ResMut, ci: Res) { if ci.is_server() { start_server(net); } else { start_client(net); } } fn start_server(mut net: ResMut) { net.bind(SERVER).unwrap(); } fn start_client(mut net: ResMut) { net.bind(CLIENT).unwrap(); } struct MessageTimerState { message_timer: Timer, } impl Default for MessageTimerState { fn default() -> Self { MessageTimerState { message_timer: Timer::from_seconds(5.0, true), } } } fn send_messages( ci: Res, time: Res