[SOLVED] Help me listen to broadcast (Windows)


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(""));

    let mut buf = [0; 10];
    let (bytes_count, source) = try!(socket.recv_from(&mut buf));
    println!("Recieved {} from {:?}", bytes_count, source);

fn main() {
    println!("{:?}", listen_to_broadcasts());

The results:
Err(Error { repr: Os { code: 10049, message: "The requested address is not valid in its context." } })


Did you try to bind on ‘’? You may have to disable the Windows firewall.

EDIT: I just tested and it works with (even without socket.set_broadcast(true)).
EDIT2: It’s weird that the Windows firewall didn’t ask me if I wanted to allow this process. Maybe it can be added manually.

#3 works. For some reason I thought I should listen to broadcast on the broadcast address :sweat_smile:

Thanks :thumbsup: