From b3f1505d150e3efeafa089306504ec6943b76fb2 Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Thu, 13 Jun 2024 05:57:54 +0300 Subject: [PATCH] Fix examples running on LAN (#290) - We should bind "0.0.0.0" for UdpSocket. - ` public_addresses` is not needed with `ServerAuthentication::Unsecure`. --- bevy_replicon_renet/examples/simple_box.rs | 7 +++---- bevy_replicon_renet/examples/tic_tac_toe.rs | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/bevy_replicon_renet/examples/simple_box.rs b/bevy_replicon_renet/examples/simple_box.rs index ab633521..2c2e69c7 100644 --- a/bevy_replicon_renet/examples/simple_box.rs +++ b/bevy_replicon_renet/examples/simple_box.rs @@ -89,14 +89,13 @@ impl SimpleBoxPlugin { }); let current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?; - let public_addr = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), port); - let socket = UdpSocket::bind(public_addr)?; + let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, port))?; let server_config = ServerConfig { current_time, max_clients: 10, protocol_id: PROTOCOL_ID, authentication: ServerAuthentication::Unsecure, - public_addresses: vec![public_addr], + public_addresses: Default::default(), }; let transport = NetcodeServerTransport::new(server_config, socket)?; @@ -130,7 +129,7 @@ impl SimpleBoxPlugin { let current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?; let client_id = current_time.as_millis() as u64; let server_addr = SocketAddr::new(ip, port); - let socket = UdpSocket::bind((ip, 0))?; + let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0))?; let authentication = ClientAuthentication::Unsecure { client_id, protocol_id: PROTOCOL_ID, diff --git a/bevy_replicon_renet/examples/tic_tac_toe.rs b/bevy_replicon_renet/examples/tic_tac_toe.rs index afe6cbb7..5aba126b 100644 --- a/bevy_replicon_renet/examples/tic_tac_toe.rs +++ b/bevy_replicon_renet/examples/tic_tac_toe.rs @@ -262,14 +262,13 @@ impl TicTacToePlugin { }); let current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?; - let public_addr = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), port); - let socket = UdpSocket::bind(public_addr)?; + let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, port))?; let server_config = ServerConfig { current_time, max_clients: 1, protocol_id: PROTOCOL_ID, authentication: ServerAuthentication::Unsecure, - public_addresses: vec![public_addr], + public_addresses: Default::default(), }; let transport = NetcodeServerTransport::new(server_config, socket)?; @@ -290,7 +289,7 @@ impl TicTacToePlugin { let current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?; let client_id = current_time.as_millis() as u64; let server_addr = SocketAddr::new(ip, port); - let socket = UdpSocket::bind((ip, 0))?; + let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0))?; let authentication = ClientAuthentication::Unsecure { client_id, protocol_id: PROTOCOL_ID,