1
votes

I have written a C++ application to send/receive UDP message thorough sockets. The application is able to send/receive both multicast and unicast messages.

I want to know, is it OK to use single port for both multicast and unicast messages? OR is it better to have separate ports for unicast and multicast messages?

I am expecting approx 100+ messages per second including both unicast and multicast.

2
It's fine. And unless you're on a seriously ghetto system, the load you're expecting shouldn't even have a noticeable effect. - tmyklebu

2 Answers

2
votes

As long as you have only one socket, there is no problem receiving both unicast and multicast traffic.

If on the other hand you have two sockets open on the same port, you might see some inconsistent behavior with unicast.

With two sockets on the same port, any multicast traffic that arrives on that point will be sent to both sockets. However, incoming unicast traffic with either appear on both sockets or on one of the two sockets randomly. The exact behavior depends on the OS in question.

Since you want to receive both unicast and multicast, use a single socket. Don't use multiple sockets on the same port unless you're working with multicast only.

1
votes

Should be fine. Just don't bind to the multicast address or the network interface address (use 0.0.0.0:port) and don't connect to a remote address. You will see all traffic that goes to this port.