Question

Which would be a faster/more efficient implementation when one server is broadcasting to multiple clients: MulticastSocket or DatagramSocket?

Please discuss an explanation too, thank you!

The messages passed involve strings and floating point numbers.

Was it helpful?

Solution

The deciding factor is usually whether the clients are on the same, or otherwise multicast enabled/linked networks. In general, Multicast is going to be MUCH more efficient than any form of unicasting, however, multicasting is not reliable, and does not work across heterogeneous networks like the internet, where the operators tend to disable multicast traffic.

If the data needs be reliable, then you really do need to use TCP unicasting, or alternatively add some form of FEC to the multicast to impart a semblance of reliability to the data stream, and if the traffic needs to travel across the internet, then you MUST use unicast TCP or UDP.

Short version: If your data is small, needs to be reliable, traverses the internet or is sent infrequently, use unicast. If your data is large, delivered to a large number of clients, can tolerate some lossiness, and only traverses networks you control or which are multicast enabled, use multicast. Multicast is really a one trick pony, (unreliable data broadcast over a homogenous network) whereas unicast can do most anything, but with higher overhead.

Note: TCP beyond a certain amount of data loss ceases to be reliable as well, (causing disconnects) and the added traffic from unicasting can push that limit down as it multiplies the amount of data flow. FEC adds a relatively fixed overhead for even a very large number of clients, but there's a point where neither FEC nor unicasting help anymore, and you simply need to reengineer the network to achieve a workable solution.

OTHER TIPS

Multi-cast is the best option if you have clients on multiple sub-networks. Broadcast can be marginally more efficient if you are sending data only one sub-network. However multi-cast is usually used as the difference is pretty tenuous.

What the data contains is not important.

You may find that if you need reliable delivery, that using TCP is simpler and can even be faster in some cases (as routers tend to be optimised for TCP) If delivery doesn't need to be reliable use multicast.

Your question is unclear. If you are broadcasting it doesn't make any difference whether you use DatagramSocket or MulticastSocket. If you are asking whether multicast is more efficient than broadcast, (a) the answer is 'yes', and (b) you must use MulticastSocket for receiving the multicasts; for sending them, again, you can use either DatagramSocket or MulticastSocket, and there is no difference in efficiency.

Multicasts are more efficient than datagram socket, however, it also uses UDP, and hence does not provide any guarantee that the data packet will be received by all receivers. Unless you have a managed switched in the network, which prioritizes your packets, you are most likely to loose packets in any random order irrespective of your network usage.

If you have limited number of devices in your network that needs to listener to multicast, I would suggest to do a TCP unicast to each device, and use some sort of network service discovery to find your devices.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top