diff --git a/alvr/client_core/src/connection.rs b/alvr/client_core/src/connection.rs index c003a0b35f..cb7ad87ba4 100644 --- a/alvr/client_core/src/connection.rs +++ b/alvr/client_core/src/connection.rs @@ -47,7 +47,9 @@ const INITIAL_MESSAGE: &str = concat!( "Open ALVR on your PC then click \"Trust\"\n", "next to the client entry", ); -const NETWORK_UNREACHABLE_MESSAGE: &str = "Cannot connect to the internet"; +const NETWORK_UNREACHABLE_MESSAGE: &str = "Cannot connect to the streamer.\nNetwork error."; +const SUCCESS_CONNECT_MESSAGE: &str = "Successful connection!\nPlease wait..."; +const LOCAL_TRY_MESSAGE: &str = "Trying to connect to localhost..."; // const INCOMPATIBLE_VERSIONS_MESSAGE: &str = concat!( // "Streamer and client have\n", // "incompatible types.\n", @@ -135,24 +137,32 @@ fn connection_pipeline( return Ok(()); } - if let Err(e) = announcer_socket.broadcast() { - warn!("Broadcast error: {e:?}"); + let mut is_broadcast_ok = false; + if let Err(e) = announcer_socket.announce_broadcast() { + debug!("Couldn't announce to localhost, retrying on local... {e:}"); - set_hud_message(NETWORK_UNREACHABLE_MESSAGE); - - thread::sleep(RETRY_CONNECT_MIN_INTERVAL); - - set_hud_message(INITIAL_MESSAGE); - - return Ok(()); + set_hud_message(LOCAL_TRY_MESSAGE); + } else { + is_broadcast_ok = true; } if let Ok(pair) = ProtoControlSocket::connect_to( DISCOVERY_RETRY_PAUSE, PeerType::Server(&listener_socket), ) { + set_hud_message(SUCCESS_CONNECT_MESSAGE); break pair; } + + if !is_broadcast_ok { + warn!("Couldn't announce to network or connect to localhost."); + set_hud_message(NETWORK_UNREACHABLE_MESSAGE); + + thread::sleep(RETRY_CONNECT_MIN_INTERVAL); + + set_hud_message(INITIAL_MESSAGE); + return Ok(()); + } } }; diff --git a/alvr/client_core/src/sockets.rs b/alvr/client_core/src/sockets.rs index 1a0607596a..e3a46228bd 100644 --- a/alvr/client_core/src/sockets.rs +++ b/alvr/client_core/src/sockets.rs @@ -20,7 +20,7 @@ impl AnnouncerSocket { Ok(Self { socket, packet }) } - pub fn broadcast(&self) -> Result<()> { + pub fn announce_broadcast(&self) -> Result<()> { self.socket .send_to(&self.packet, (Ipv4Addr::BROADCAST, CONTROL_PORT))?; diff --git a/wiki/Use-ALVR-through-a-USB-connection.md b/wiki/Use-ALVR-through-a-USB-connection.md index fc0fa5c248..8daff05ac4 100644 --- a/wiki/Use-ALVR-through-a-USB-connection.md +++ b/wiki/Use-ALVR-through-a-USB-connection.md @@ -10,7 +10,6 @@ * If your headset is detected, click "Trust." Click "Edit", "Add new" and change the IP address to `127.0.0.1`. * If your headset is not detected, click "Add client manually" and use the IP address `127.0.0.1`. Use the hostname displayed on your headset screen. -* Turn off client discovery in Settings > Connection. * Switch the connection streaming protocol to TCP in Settings > Connection. ## Letting your PC communicate with your HMD