I am developing an application in Rust using UDP sockets. The problem I encounter is that sometimes, the send_to
function fails with an error saying Os { code: 1, kind: PermissionDenied, message: "Operation not permitted" }
I create the UDP socket using -
let socket = UdpSocket::bind(("0.0.0.0", 0)).expect("unable to create socket")
Using 0
as port so its automatically assigned.
I found a similar issue shown here with C++ without any explanation of what the error means or how to resolve it. In another post here it is mentioned that the kernel drops some of the packets. The solution there alters the system configuration.
So, what does this error mean and what could be a solution to deal with this? Even in the docs for sent_to
no such error is mentioned.
As mentioned in the C++ post it is very rare and is hard to debug.
EDIT:
The I am using send_to
as
socket.send_to(&sequence_data, address).expect("Couldn't send sequence")
Here,
address
is aSocketAddr
with value127.0.0.1:<port>
. The port is decided at runtime.sequence_data
is aVec<u8>
socket
is aUdpSocket