🐣 so that's how multicast groups work
commit
73b93d99af
|
@ -0,0 +1 @@
|
|||
/target
|
|
@ -0,0 +1,16 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.48"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62e1f47f7dc0422027a4e370dd4548d4d66b26782e513e98dca1e689e058a80e"
|
||||
|
||||
[[package]]
|
||||
name = "lookaround"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
]
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "lookaround"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.48"
|
|
@ -0,0 +1,52 @@
|
|||
use std::{
|
||||
env,
|
||||
net::{
|
||||
Ipv4Addr,
|
||||
UdpSocket,
|
||||
},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use anyhow::{
|
||||
self,
|
||||
Result,
|
||||
bail,
|
||||
};
|
||||
|
||||
fn main () -> Result <()> {
|
||||
let mut args = env::args ();
|
||||
|
||||
let _exe_name = args.next ();
|
||||
|
||||
match args.next ().as_ref ().map (|s| &s[..]) {
|
||||
None => bail! ("First argument must be a subcommand"),
|
||||
Some ("client") => client ()?,
|
||||
Some ("server") => server ()?,
|
||||
Some (x) => bail! ("Unknown subcommand {}", x),
|
||||
}
|
||||
|
||||
Ok (())
|
||||
}
|
||||
|
||||
fn client () -> Result <()> {
|
||||
let socket = UdpSocket::bind ("0.0.0.0:9041").unwrap ();
|
||||
|
||||
socket.join_multicast_v4 (&(Ipv4Addr::from_str ("225.100.99.98").unwrap ()), &([0u8, 0, 0, 0].into ())).unwrap ();
|
||||
|
||||
socket.send_to ("hi there".as_bytes (), ("225.100.99.98", 9040)).unwrap ();
|
||||
|
||||
Ok (())
|
||||
}
|
||||
|
||||
fn server () -> Result <()> {
|
||||
let socket = UdpSocket::bind ("0.0.0.0:9040").unwrap ();
|
||||
|
||||
socket.join_multicast_v4 (&(Ipv4Addr::from_str ("225.100.99.98").unwrap ()), &([0u8, 0, 0, 0].into ())).unwrap ();
|
||||
|
||||
let mut buf = vec! [0u8; 4096];
|
||||
let (bytes_recved, remote_addr) = socket.recv_from (&mut buf).unwrap ();
|
||||
|
||||
dbg! (bytes_recved, remote_addr);
|
||||
|
||||
Ok (())
|
||||
}
|
Loading…
Reference in New Issue