What is a multicast port number?

14,789

A multicast address includes a specific I.P. address as well as the port number. And this is not what we traditionally think of the i.p. address of the machine (either client or server), which is part of the unicast protocol.

Multicast addresses, in IPV4 terms, are 224.n.n.n to 239.n.n.n

Basically the first 4 bits of the adress are 1110

There are specific sub-ranges within that for defined purposes.

You basically pick an address and a port that no other app is using. You probably want to use an address in the 239.n.n.n range, because that's reserved for 'administratively scoped' - which is basically "stay on my network" (although a network engineer would probably have a fit at that description).

Here's an example, which shows a client and server connecting: http://www.jarloo.com/c-udp-multicasting-tutorial/

(Code formatting fails in the middle, where the end of the server and the start of the client have merged together, with some stuff that's supposed to be text, but you'll work that out).

See they both connect on the same i.p. address, and the same port.

This page has an illustration of what I mean with the first for bits being 1110, and links to a discussion of ipv6 multicasting: http://www.tcpipguide.com/free/t_IPMulticastAddressing.htm (and also quite a lot of information about unicast, which is what most internet traffic is).

And of course Wikipedia has a bit of a discussion as well.
https://en.wikipedia.org/wiki/Multicast_address

Share:
14,789
Ryan
Author by

Ryan

Updated on June 22, 2022

Comments

  • Ryan
    Ryan almost 2 years

    I'm having some trouble with the C# .NET framework Socket class when trying to bind a socket to a multicast IP address. In Microsoft's documentation (see link below) for the Bind() method, they warn that "If you intend to receive multicast datagrams, you must call the Bind method with a multicast port number."

    I don't believe port numbers are muliticast/unicast/broadcast specific. Do you know what Microsoft means by this?

    https://msdn.microsoft.com/en-us/library/system.net.sockets.socket.bind(v=vs.110).aspx

    • Ron Maupin
      Ron Maupin over 3 years
      Multicast must use UDP, and UDP uses port numbers for its addresses. A process will bind to a specific UDP port number, even for multicast.
  • Ryan
    Ryan almost 7 years
    I understand what a multicast address is, but what does Microsoft mean by a "multicast port number?" They seem to be implying that only some port numbers can be used for multicast addresses.
  • Ron Maupin
    Ron Maupin almost 7 years
    @Ryan, a port number is an address of a layer-4 protocol, and it really has nothing to do with a multicast (IP, layer-3) address. If the layer-4 protocol you use for multicast is UDP (common), then UDP requires a port number. UDP has no idea if you are using unicast, broadcast, or multicast.
  • Ryan
    Ryan almost 7 years
    That's what I thought. But what does Microsoft mean by a "multicast port number?"
  • Ron Maupin
    Ron Maupin over 3 years
    Multicast uses UDP, but it cannot use TCP because TCP creates a connection between exactly two hosts, while multicast sends traffic to multiple hosts. Multicast uses UDP because UDP is connectionless.
  • yamex5
    yamex5 over 3 years
    @RonMaupin You are correct, I had forgotten that and I'll edit my answer. Thanks!