Reputation: 391
Since it is possible to construct a tcp socket and a udp socket that listens on the same port, is it possible to construct multiple sockets that listen for udp messages on the same port, with each listening for different source endpoints?
Design-wise, I'm currently under the impression that the 'correct' way to do it is just to have a single socket listening for all udp messages and have it determine the origin at the application level.
Upvotes: 2
Views: 2209
Reputation: 596256
It is possible to have multiple UDP sockets listening on the same local IP/Port pair by using the SO_REUSEADDR
socket option, but there is no way to tell each socket to only accept packets for its intended remote IP/Port pair, so there is no guarantee which socket will receive which packet. So yes, the correct option is to use a single socket that looks at the sending IP/Port of each received packet and directs the packet accordingly.
Upvotes: 3