Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

The DatagramSocketImpl in Java has a joinGroup method that takes a socket address (IP and PORT) plus the interface address (IP and PORT). I am trying to understand the difference and purpose of each of those three addresses in the multicast stack:

  1. What is the purpose of the bind address? Does it need a port?
  2. What is the purpose of the interface address? Does it need a port?
  3. What is the purpose of the multicast address? Does it need a port?

I am confused: I don't know the difference between the bind address and the interface address. Also, I am not sure if the multicast address really needs a port. Can I call the IP of the multicast address the multicast address group?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

There are actually three methods you mix up here. The first one is bind which is used to bind the socket to a specified address and port. Using this method basically you open a udp-port and wait for data to this port on that address. The second one is the join-method which is used to let a socket join a specified multicast-group. An example of a multicast-group is 224.0.0.1 - the "All hosts" multicast-group - which addresses all hosts on the same network segment. The third method is joinGroup which lets a socket join a specified multicast-group on a specified network interface. As you can see method two and three are used for IP multicasting and method one is used for UDP (not necessarily in combination with multicasting). By joining a multicast group the socket is able to receive datagrams sent using IP multicasting. Both can of course be combined, for example receive data using multicasting and then if necessary reply either using multicasting (if the data is interesting for all hosts in the group) or directly to the sender (if the data is only interesting for the sender).

  1. When you bind a socket to an address using the bind method this also involves a port. Only datagrams for that specific address/port-combination are/can be received unless the socket also joins a multicast-group.

  2. I'm not sure how you got from joinGroup to interface address. What you need is a SocketAddress and a NetworkInterface. The NetworkInterface can either be retrieved by interface name (NetworkInterface.getByName) or by address (NetworkInterface.getByInetAddress). In the case of getByInetAddress you could probably call it the interface address but all it does is to retrieve the NetworkInterface that has the specified address and thus does not use a port-number.

  3. Multicast-addresses are used in IP Multicasting which is used to send IP datagrams to a group of hosts (if they are interested in receiving the datagrams). You can use a port (if you use UDP) but you don't need to. The CIDR of the IPv4 multicast-addresses is 224.0.0.0/4 (224.0.0.0 - 239.255.255.255) and IPv6 multicast-addresses have the prefix ff00::/8. Each IP address in those ranges represents a multicast-group. There are different blocks of multicast addresses (and multicast groups) which are to be handled differently. For example 224.0.0.0/24 are not to be routed out of their originating subnet, while 239.192.0.0/14 can be routed and if routed globally have to be encapsulated.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.