Closed fillobotto closed 3 years ago
Thank you for reporting this issue! I am not actually sure if this is a feature or a bug 🤔 Also, I am not sure if there is a way to figure out which ports are currently used by CoAP servers as they are probably not sharing a global variable. Maybe this is something that has to be checked for in your application. I will also have a look into the server implementation, though, and see if it can be fixed there :)
In my experience with TCP native sockets, you can't bind a socket on the same address and port in your local machine. So it is actually something that should be raised by the "native" side of the coap library. No global variables should be needed. I don't know if this actually applies to UDP.
I now found the reason why reusing the same port for two servers works: The parameter reuseAddr
is set to true
when the dgram.createSocket
method is called:
I am not sure, however, if this is actually a problem and an error should be thrown if the same address/port combination is being used. If I am not mistaken, only the first server that starts listening (edit: to message/request events apparently) will receive incoming messages anyway.
I'm using coap 0.25.0 and trying to listen to the same port using two separate Coap server instances and I though it would have thrown error when attempting to listen again on the same port using
listen(port, address, done)
. It comes out I am wrong, but is it a bug or what?Here's a minimal sample of what I mean:
Both the
done
callbacks correctly return anderr
is undefined. Shouldn't the second call return an error? Or I just have to assume that multiple servers can listen to connections on the same port?