Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MulticastSocket vs. DatagramSocket in Broadcasting to Multiple Clients

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.

like image 730
brain56 Avatar asked Dec 28 '22 09:12

brain56


2 Answers

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.

like image 132
SplinterReality Avatar answered Feb 20 '23 05:02

SplinterReality


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.

like image 27
Peter Lawrey Avatar answered Feb 20 '23 05:02

Peter Lawrey