Skip to content

Commit

Permalink
fix(connection): 🐛 Try localhost if broadcast fails, fixes wifi being…
Browse files Browse the repository at this point in the history
… required for cabled (#1962)

* fix(connection): 🐛 Try localhost if broadcast fails, fixes wifi being required for cabled

* fix(connection): 🐛 use separate functions for local and broadcast socket sends

* Fixed connection pipeline assuming broadcast works in tcp
  • Loading branch information
Meister1593 authored Feb 4, 2024
1 parent 7940952 commit ab4f57c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
30 changes: 20 additions & 10 deletions alvr/client_core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(());
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion alvr/client_core/src/sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?;

Expand Down
1 change: 0 additions & 1 deletion wiki/Use-ALVR-through-a-USB-connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ab4f57c

Please sign in to comment.