"Unable to assign the requested address" when sending to UdpSocket

let addr = "239.255.255.250:1982";
let socket = UdpSocket::bind(addr).unwrap();
let message = "some message".as_bytes();
socket.send_to(message, addr).unwrap();

This code gives the following error for the last line:

Error { repr: Os { code: 49, message: "Can\'t assign requested address" } }

Why so?

EDIT: I tried the following:

let addr = "239.255.255.250:1982";
let socket = UdpSocket::bind("127.0.0.1:34254").unwrap();
let message = "some message".as_bytes();
socket.send_to(message, addr).unwrap();

But that didn’t change anything, unfortunately.

+4
source share
2 answers

Inspired by this answer , I changed the address to "0.0.0.0:34254" and it worked:

let addr = "239.255.255.250:1982";
let socket = UdpSocket::bind("0.0.0.0:34254").unwrap();
let message = "some message".as_bytes();
socket.send_to(message, addr).unwrap();
0
source

The address you used to bind your UdpSocketto is the multicast address.

The argument UdpSocket::bindmust be the local address you are sending.

127.0.0.1:34254. , . , .

+5

Source: https://habr.com/ru/post/1694508/