I am not able to bind to broadcast because I don't know how to set the broadcast option before binding.
Here is my code:
use std::net::UdpSocket;
fn listen_to_broadcasts() -> std::io::Result<()> {
// How do I swap the following two lines ???
let mut socket = try!(UdpSocket::bind("255.255.255.255:8892"));
try!(socket.set_broadcast(true));
let mut buf = [0; 10];
let (bytes_count, source) = try!(socket.recv_from(&mut buf));
println!("Recieved {} from {:?}", bytes_count, source);
Ok(())
}
fn main() {
println!("Hello!");
println!("{:?}", listen_to_broadcasts());
println!("Bye!");
}
The results:
Err(Error { repr: Os { code: 10049, message: "The requested address is not valid in its context." } })