Skip to content

Commit

Permalink
fix(connection): šŸ› use separate functions for local and broadcast socā€¦
Browse files Browse the repository at this point in the history
ā€¦ket sends
  • Loading branch information
Meister1593 committed Jan 15, 2024
1 parent f886a8b commit 81123d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions alvr/client_core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ fn connection_pipeline(
return Ok(());
}

if let Err(e) = announcer_socket.announce_to(Ipv4Addr::BROADCAST) {
if let Err(e) = announcer_socket.announce_broadcast() {
warn!("Global broadcast error. Is network available? {e:?}");

set_hud_message(LOCAL_TRY_MESSAGE);

thread::sleep(RETRY_CONNECT_MIN_INTERVAL);

if let Err(e) = announcer_socket.announce_to(Ipv4Addr::LOCALHOST) {
if let Err(e) = announcer_socket.announce_local() {
warn!("Couldn't announce to neither network or localhost. {e:?}");
set_hud_message(NETWORK_UNREACHABLE_MESSAGE);

Expand Down
12 changes: 10 additions & 2 deletions alvr/client_core/src/sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@ impl AnnouncerSocket {
Ok(Self { socket, packet })
}

pub fn announce_to(&self, addr: Ipv4Addr) -> Result<()> {
self.socket.send_to(&self.packet, (addr, CONTROL_PORT))?;
pub fn announce_local(&self) -> Result<()> {
self.socket
.send_to(&self.packet, (Ipv4Addr::LOCALHOST, CONTROL_PORT))?;

Ok(())
}

pub fn announce_broadcast(&self) -> Result<()> {
self.socket
.send_to(&self.packet, (Ipv4Addr::BROADCAST, CONTROL_PORT))?;

Ok(())
}
Expand Down

0 comments on commit 81123d5

Please sign in to comment.