Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Can't assign requested address" when sending to a UdpSocket

Tags:

sockets

rust

udp

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 would that be the case?

EDIT: I tried the following as suggested:

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.

like image 320
Sarp Başaraner Avatar asked Mar 06 '18 07:03

Sarp Başaraner


1 Answers

The address you used to bind your UdpSocket to is a multicast address.

The argument to UdpSocket::bind should be the local address you send from.

The docs use 127.0.0.1:34254. If it is not currently being used, this should work for you. Additionally you can give it an array of potential adresses to use.

like image 195
Neikos Avatar answered Oct 01 '22 02:10

Neikos