Is broadcasting via TCP possible?

44,168

Solution 1

As everyone has said that is not possible with TCP, it is unicast only. However there are implementations of reliable multicast, which should give you multicast with the reliability of TCP. See wikipedia, especially Pragmatic General Multicast.

Solution 2

No, there isn't. For example, the concept of window size and how it's adjusted becomes completely meaningless if you're trying to talk to multiple parties.

It might be possible to create a new protocol that shared many of the attributes of TCP while allowing multicast. But I think it would be highly problematic. For example, the speed at which recipients received data would be constrained by the limitations of the slowest receiver. The sender has to manage buffer space so that even the slowest receiver can get re-transmissions if necessary.

No, I think protocols for doing multicast are always going to have to be very special purpose and focused on the exact problem at hand. Something generalized and TCP-like just isn't feasible.

There are ways to do reliable multicast bulk data transfer. The basic idea is to use erasure codes to continuously transmit information in a sort of loop. Then a recipient can just start receiving packets until they have enough to reconstruct the original file.

But these don't seem to fit your scenario all that well.

Solution 3

Your SendToAll() will need to iterate through all open sockets and write the data to each one independently.

Broadcast and multicast are limited to UDP sockets only.

Solution 4

Consider looking at overlay networks, or simply using a messaging middleware that provides publish semantics such as ØMQ which also conveniently provides a BSD socket API.

Share:
44,168
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm writing a server/client system in C, which uses BSD Sockets under a TCP connection. The server is multi-threaded, with each connection running in its own receptor. Each client does a good job talking with the server on a one-to-one basis, sadly I can't think of a way to implement a SendToAll() function, for instance, if client A does something that requires sending a packet to all of the clients. How would I do this?

    I was considering implementing a queue in every receptor, and any broadcast gets sent to those queues; when the receptor sends out a new packet, it adds that message onto the packet as well, if that makes any sense.

    But yeah, is there any way to broadcast via TCP, like you can via UDP?

  • TOMKA
    TOMKA over 13 years
    That's not quite true, there are other protocols that allow multicast and broadcasting, for example, there is PGM.
  • TOMKA
    TOMKA over 13 years
  • Omnifarious
    Omnifarious over 13 years
    @dreamlax - Interesting. I do know about ideas for reliable multicast bulk data transfer. This involves using erasure codes and just re-transmitting on a loop. That way a recipient can start picking things up in the middle and just continue receiving until they had enough data to reconstruct the entire file.