Reputation: 8293
In a discussion on SO_REUSEPORT, the following question was posted to reddit, but there was no answer. I am wondering if Stack Overflow knows the answer.
Can anyone tell me how this interacts with multicast?
I've got an application where the program should listen to multicast UDP messages, and this program may be started multiple times on the same computer. When a message comes it, all listening processes should get it.
I've noticed that on Linux, it works fine if I don't set SO_REUSEPORT, and if I understand correctly, setting SO_REUSEPORT may be the wrong thing to do -- I don't want UDP messages distributed between the processes, I want all processes to get a copy. However, on OS X, the second execution of the program fails to find a free port unless SO_REUSEPORT is set.
tl;dr: Is it expected to set SO_REUSEPORT when using multicast?
Upvotes: 2
Views: 4596
Reputation: 4666
WIth SO_REUSEPORT, one can bind multiple sockets to the same port and address. The only requirement is that earlier sockets must have set this option. Thus, if we want two sockets, sock1 and sock2 to be bound ot the same port (and address), then s2 would be able to reuse the port/address only if both sock1 and sock2 set SO_REUSEPORT. WIth respect to multicast, if both sock1 and sock2 are recievers of the same multicast group, then they would both get a copy of data.
You might find this answer helpful: Socket options SO_REUSEADDR and SO_REUSEPORT, how do they differ? Do they mean the same across all major operating systems?
Upvotes: 2