🐛 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.
main
_ 2021-12-08 21:31:07 -06:00
parent 0bb702f312
commit fd4f70b1c9
1 changed files with 6 additions and 18 deletions

View File

@ -12,28 +12,13 @@ pub async fn server <I: Iterator <Item=String>> (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 &params.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 <I: Iterator <Item=String>> (mut args: I) -> Result <Params, AppErr
})
}
async fn serve_interface (params: Params, socket: UdpSocket)
async fn serve_interface (
params: Params,
socket: UdpSocket,
)
-> Result <(), AppError>
{
let mut recent_idem_ids = Vec::with_capacity (32);