Tuesday, March 30, 2010

How to do Multicast and Broadcast ? Is it possible for both TCP and UDP

Multicast can not happen on TCP it works only in UDP or RAW socket.
Same applies to Broadcast also .

TCP sockets are always Unicast.

A reliable multicast protocol, like PGM(Pragmatic General Multicast ), adds the ability for receivers to detect lost and/or out-of-order messages and take corrective action (similar in principle to TCP), resulting in a gap-free, in-order message stream.

http://tldp.org/HOWTO/Multicast-HOWTO-6.html

Monday, March 29, 2010

Can two application Listen on same port

No. Only one process can bind to a port on an address at any one time. You can bind two processes to the same port number, but on different IP addresses Different NIC , hence different ports.

For UDP (Multicasts), multiple applications can subscribe to the same port.
With multicast sockets more than one application can bind to a port as long as SO_REUSEADDR is set in each socket's options.
We can  accomplish this by writing a "master" process, which accepts and processes all connections, then hands them off to your two applications who need to listen on the same port. This is the approach that Web servers and such take, since many processes need to listen to 80.