From fd4f70b1c92f7f4cba2692e4d4175f65a53360bc Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Wed, 8 Dec 2021 21:31:07 -0600 Subject: [PATCH] :bug: bug: think I figured out the server part turns out you can join multiple multicast groups on the same socket. And then I think the OS or the network somehow decides how to route packets to you. Without touching anything else, if I'm plugged into Ethernet, it picks that address (when running client on the desktop) and when I unplug it, it picks the laptop's WiFi. --- src/server.rs | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/server.rs b/src/server.rs index 4aa5b19..261a593 100644 --- a/src/server.rs +++ b/src/server.rs @@ -12,28 +12,13 @@ pub async fn server > (args: I) -> Result <(), AppErro { let params = configure (args)?; - // This was too hard to do in a functional style - let mut tasks = vec! []; + let socket = UdpSocket::bind (SocketAddrV4::new (Ipv4Addr::UNSPECIFIED, params.common.server_port)).await?; for bind_addr in ¶ms.bind_addrs { - let socket = match UdpSocket::bind (SocketAddrV4::new (Ipv4Addr::UNSPECIFIED, params.common.server_port)).await { - Err (e) => { - println! ("Error binding socket: {:?}", e); - continue; - }, - Ok (x) => x, - }; - socket.join_multicast_v4 (params.common.multicast_addr, *bind_addr)?; - - dbg! (bind_addr); - - tasks.push (tokio::spawn (serve_interface (params.clone (), socket))); } - for task in tasks { - task.await??; - } + serve_interface (params, socket).await?; Ok (()) } @@ -80,7 +65,10 @@ fn configure > (mut args: I) -> Result Result <(), AppError> { let mut recent_idem_ids = Vec::with_capacity (32);