UDP multicasting with channels

We can also multicast with channels. We will use IPv6 to demonstrate this process. The process is similar to our previous use of the DatagramChannel class, except that we need to use a multicast group. To do this, we need to know which network interfaces are available. Before we get into the specifics of using channels to multicast, we will demonstrate how to obtain a list of network interfaces for a machine.

The NetworkInterface class represents a network interface. This class was discussed in Chapter 2, Network Addressing. The following is a variation of the approach demonstrated in that chapter. It has been augmented to show whether a specific interface supports multicasting, as shown next:

 try { Enumeration<NetworkInterface> ...

Get Learning Network Programming with Java now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.