How to use SO_REUSEADDR on UdpSocket?

hey, i am using udp to join a multicast,
and the local bind addr will be 0.0.0.0:remote_multicast_ip_port,

when just one process , it will be work correctly, but when running two process,

Os { code: 98, kind: AddrInUse, message: "Address already in use" }

error caused,

and i find the SO_REUSEADDR may help me. but i can't find the API about SO_REUSEADDR in UdpSocket.

appreciate for your advice.

1 Like

GitHub - rust-lang/socket2: Advanced configuration options for sockets. contains the reuseport option.

but not include the std

It looks like the UdpSocket type only provides a way to set SO_BROADCAST... that said, you could always use OS-specific APIs to do the same thing (e.g. on Linux, use the AsRawFd impl to get the socket's file descriptor then call nix::sys::socket::setsockopt() to set the ReuseAddr option).

it's complex for me , i trying use socket2 instead,
0.0

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.