Struct multicast_socket::MulticastSocket
source · pub struct MulticastSocket { /* private fields */ }
Implementations§
source§impl MulticastSocket
impl MulticastSocket
sourcepub fn all_interfaces(multicast_address: SocketAddrV4) -> Result<Self>
pub fn all_interfaces(multicast_address: SocketAddrV4) -> Result<Self>
Examples found in repository?
examples/mdns.rs (line 19)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
fn main() {
let mdns_multicast_address = SocketAddrV4::new([224, 0, 0, 251].into(), 5353);
// Validate that building with options works with the public API
let with_options = MulticastSocket::with_options(
mdns_multicast_address,
multicast_socket::all_ipv4_interfaces()
.expect("could not fetch all interfaces for options"),
multicast_socket::MulticastOptions {
..Default::default()
},
)
.expect("validate that we are starting with options");
drop(with_options);
let socket = MulticastSocket::all_interfaces(mdns_multicast_address)
.expect("could not create and bind socket");
let data = vec![1, 2];
socket
.broadcast(&data)
.expect("could not broadcast message to ips being listened");
loop {
if let Ok(message) = socket.receive() {
dbg!(&message.interface);
dbg!(&message.origin_address);
let data = vec![9, 8, 7];
socket
.send(&data, &message.interface)
.expect("could not send data");
};
}
}
sourcepub fn with_options(
multicast_address: SocketAddrV4,
interfaces: Vec<Ipv4Addr>,
options: MulticastOptions
) -> Result<Self>
pub fn with_options( multicast_address: SocketAddrV4, interfaces: Vec<Ipv4Addr>, options: MulticastOptions ) -> Result<Self>
Examples found in repository?
examples/mdns.rs (lines 8-15)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
fn main() {
let mdns_multicast_address = SocketAddrV4::new([224, 0, 0, 251].into(), 5353);
// Validate that building with options works with the public API
let with_options = MulticastSocket::with_options(
mdns_multicast_address,
multicast_socket::all_ipv4_interfaces()
.expect("could not fetch all interfaces for options"),
multicast_socket::MulticastOptions {
..Default::default()
},
)
.expect("validate that we are starting with options");
drop(with_options);
let socket = MulticastSocket::all_interfaces(mdns_multicast_address)
.expect("could not create and bind socket");
let data = vec![1, 2];
socket
.broadcast(&data)
.expect("could not broadcast message to ips being listened");
loop {
if let Ok(message) = socket.receive() {
dbg!(&message.interface);
dbg!(&message.origin_address);
let data = vec![9, 8, 7];
socket
.send(&data, &message.interface)
.expect("could not send data");
};
}
}
source§impl MulticastSocket
impl MulticastSocket
sourcepub fn receive(&self) -> Result<Message>
pub fn receive(&self) -> Result<Message>
Examples found in repository?
examples/mdns.rs (line 28)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
fn main() {
let mdns_multicast_address = SocketAddrV4::new([224, 0, 0, 251].into(), 5353);
// Validate that building with options works with the public API
let with_options = MulticastSocket::with_options(
mdns_multicast_address,
multicast_socket::all_ipv4_interfaces()
.expect("could not fetch all interfaces for options"),
multicast_socket::MulticastOptions {
..Default::default()
},
)
.expect("validate that we are starting with options");
drop(with_options);
let socket = MulticastSocket::all_interfaces(mdns_multicast_address)
.expect("could not create and bind socket");
let data = vec![1, 2];
socket
.broadcast(&data)
.expect("could not broadcast message to ips being listened");
loop {
if let Ok(message) = socket.receive() {
dbg!(&message.interface);
dbg!(&message.origin_address);
let data = vec![9, 8, 7];
socket
.send(&data, &message.interface)
.expect("could not send data");
};
}
}
sourcepub fn send(&self, buf: &[u8], interface: &Interface) -> Result<usize>
pub fn send(&self, buf: &[u8], interface: &Interface) -> Result<usize>
Examples found in repository?
examples/mdns.rs (line 34)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
fn main() {
let mdns_multicast_address = SocketAddrV4::new([224, 0, 0, 251].into(), 5353);
// Validate that building with options works with the public API
let with_options = MulticastSocket::with_options(
mdns_multicast_address,
multicast_socket::all_ipv4_interfaces()
.expect("could not fetch all interfaces for options"),
multicast_socket::MulticastOptions {
..Default::default()
},
)
.expect("validate that we are starting with options");
drop(with_options);
let socket = MulticastSocket::all_interfaces(mdns_multicast_address)
.expect("could not create and bind socket");
let data = vec![1, 2];
socket
.broadcast(&data)
.expect("could not broadcast message to ips being listened");
loop {
if let Ok(message) = socket.receive() {
dbg!(&message.interface);
dbg!(&message.origin_address);
let data = vec![9, 8, 7];
socket
.send(&data, &message.interface)
.expect("could not send data");
};
}
}
sourcepub fn broadcast(&self, buf: &[u8]) -> Result<()>
pub fn broadcast(&self, buf: &[u8]) -> Result<()>
Examples found in repository?
examples/mdns.rs (line 24)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
fn main() {
let mdns_multicast_address = SocketAddrV4::new([224, 0, 0, 251].into(), 5353);
// Validate that building with options works with the public API
let with_options = MulticastSocket::with_options(
mdns_multicast_address,
multicast_socket::all_ipv4_interfaces()
.expect("could not fetch all interfaces for options"),
multicast_socket::MulticastOptions {
..Default::default()
},
)
.expect("validate that we are starting with options");
drop(with_options);
let socket = MulticastSocket::all_interfaces(mdns_multicast_address)
.expect("could not create and bind socket");
let data = vec![1, 2];
socket
.broadcast(&data)
.expect("could not broadcast message to ips being listened");
loop {
if let Ok(message) = socket.receive() {
dbg!(&message.interface);
dbg!(&message.origin_address);
let data = vec![9, 8, 7];
socket
.send(&data, &message.interface)
.expect("could not send data");
};
}
}
Auto Trait Implementations§
impl Freeze for MulticastSocket
impl RefUnwindSafe for MulticastSocket
impl Send for MulticastSocket
impl Sync for MulticastSocket
impl Unpin for MulticastSocket
impl UnwindSafe for MulticastSocket
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more