CoAPConnect / coap-pubsub-rust

MIT License
5 stars 0 forks source link

Set socket options correctly to re-use address/port #70

Open bsilverajan opened 3 months ago

bsilverajan commented 3 months ago

Running the broker throws up an error :

thread 'main' panicked at src/main.rs:595:68: called Result::unwrap() on an Err value: Os { code: 48, kind: AddrInUse, message: "Address already in use" } note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

running on localhost for unicast and multicast causes this error.

Quick fix: change port number used by unicast and multicast addresses when creating a socket.

Kavan-M commented 3 months ago

It seems that this can be fixed by building each socket using socket2 and setting nonblocking, reuse address and reuse port for each, then transforming into a tokio UdpSocket (using from_std) before binding. Doing this allows the broker to use port 5683 on unicast and multicast.

Kavan-M commented 3 months ago

The fix also works with just reuse port

https://stackoverflow.com/questions/14388706/how-do-so-reuseaddr-and-so-reuseport-differ/14388707#14388707

Basically in multicast, reuseaddr should work but for it isnt working quite as intended here.