Recent Changes - Search:

Network Programming

This website demonstrates using wikis as teaching and learning tool.

The course instructor is happy to share the teaching materials here with those who find it readable.

Network Programming in Java - Part Four: Multicast networking

A Network Programming Lecture by Steven Choy

Lecture Overview: Multicast networking - Multicast group address - Multicast protocol - Internet Multicast Backbone - Using Class MulticastSocket - Programming multicast - Testing multicast programs - Things to be done with multicast


Multicast networking

  • Put a single packet on network & it is transmitted to all interested destinations
  • Need proper network protocol & infrastructures
  • Reduce transmission traffic and server load
    • Vs. sending 1 packet to every interested destination
  • Like UDP, but send packets to multicast groups
    • Class D IP address denotes multicast group
    • 224.0.0.0 - 239.255.255.255
    • Interested destination needs to join multicast groups to receive packets (sender needs not join)

Multicast group address

An analogue
  • Class A/B/C IP address as your email address
  • Class D IP address as a Yahoo Group mailing address
    • One needs to subscribe to the Yahoo Group to receive messages
    • When a sender sends a message to the Yahoo Group, Yahoo handles and sends to all subscribers

Multicast networking protocol

  • IGMP - Internet Group Management Protocol
    • IP standard for multicasting support
The Internet Group Management Protocol (IGMP) is a communications protocol used to manage the membership of Internet Protocol multicast groups. IGMP is used by IP hosts and adjacent multicast routers to establish multicast group memberships.
IGMP is only needed for IPv4 networks, as multicast is handled differently in IPv6 networks.
  • TTL - Time To Live
    • Max number of routers a multicast packet can cross
  • Broadcast: send packet to all IP hosts in a subnet
    • Send to a special address, usually last address in subnet address range
  • Multicast: packets can cross multiple networks

MBone

  • MBone = Internet Multicast Backbone
  • Largest deployment of multicast on the Internet
  • Multicast island: network or group of adjacent networks that supports multicast
  • TCP/IP tunnelling: scheme of moving multicast packets by putting them in regular unicast IP packets
  • TTL <= 64 restricts a packet to the local multicast island

Importance & limitations

  • Importance
    • Reduce transmission traffic
    • Reduce load on network servers
  • Limitations
    • Routers & switches need to be multicast-enabled
    • Need management tools for multicast deployment
    • Complete deployment of IP multicast over Internet is very difficult
    • No security measures to protect multicast traffic now, e.g. cannot restrict group joining

Class MulticastSocket

  • Extend DatagramSocket & add multicast capabilities
  • Provide all methods of DatagramSocket
  • Multicast, broadcast, unicast all share the same set of UDP ports
    • Java has no way to query the destination address of a received packet
  • Constructors
   // transmit
   MulticastSocket() 

   // receive & transmit
   MulticastSocket(int port) 
  • Methods
   void joinGroup(InetAddress group) throws IOException
   void leaveGroup(InetAddress group) throws IOException
   void send(DatagramPacket packet, byte ttl) throws IOException
   void setTimeToLive(int ttl) throws IOException
   int getTimeToLive() throws IOException 
   setInterface, getInterface

Programming multicast

  • Similar to using DatagramSocket except
    • Sending multicast packet can specify a TTL value
    • Receiving multicast packet must join a multicast group first
  • Multiple MulticastSocket can listen to the same port in a machine (DatagramSocket cannot)
  • Cannot create MulticastSocket on a UDP port being used by a DatagramSocket in same host
  • Methods receive() and send() with TTL are synchronized

Testing multicast programs

  • Even for a single computer to be both client and server, it must be connected to a TCP/IP network with multicast support
  • A standalone Windows computer may not work
  • Connecting through ISP (dial-up or broadband) may or may not work
  • Try in a LAN

A daytime broadcast server

import java.net.*;
import java.io.*;
import java.util.*;

public class DaytimeBroadcastServer {

   public static final int defaultPort = 1234;

   public static void main (String args[]) throws Exception {
      if (args.length > 1 ) throw new IllegalArgumentException
         ("Syntax: DaytimeBroadcastServer [<multicastgroup>]");
      InetAddress multicastGroup = InetAddress.getByName(
         args.length==0 ? "234.5.6.7": args[0]);
      MulticastSocket socket = new MulticastSocket();
      // socket.joinGroup(multicastGroup);
      while (true) {
         Thread.sleep(5000);
         System.out.println("Broadcast Data ...");
         String str = (new Date()).toString();
         byte[] data = str.getBytes();
         DatagramPacket packet = new DatagramPacket(
            data, data.length, multicastGroup, defaultPort);
         socket.send(packet);
      }
   }
}

A daytime broadcast client

import java.net.*;
import java.io.*;
import java.util.*;

public class DaytimeBroadcastClient {

   public static void main (String args[]) throws Exception {
      if (args.length > 1 ) throw new IllegalArgumentException
         ("Syntax: DaytimeBroadcastServer [<multicastgroup>]");
      InetAddress multicastGroup = InetAddress.getByName(
         args.length==0 ? "234.5.6.7": args[0]);
      MulticastSocket socket = new MulticastSocket(
         DaytimeBroadcastServer.defaultPort);
      socket.joinGroup(multicastGroup);
      byte[] buffer = new byte[80];
      DatagramPacket packet = new DatagramPacket (buffer, buffer.length);
      socket.receive(packet);
      String str = new String(packet.getData());
      System.out.println("Time received from " + packet.getAddress() + " is: " + str);
   }
}

Things to be done with multicast

  • Radio broadcasting on Internet
  • Watching live lectures via Internet
  • Real-time collaborating with shared virtual whiteboard
  • Read-time video-conferencing
  • Huge computer game with hundreds of users
  • Automatic software upgrade & bug-fix

Questions

  • Calculate the percentage of the IPv4 addresses that are reserved for IP multicasting purposes.
  • Is it necessary for a host that sends packets to a multicast group to also be a group member? Why/why not?
  • What is meant by a multicast island in MBone?
  • Can you create a MulticastSocket that listens and transmits on a UDP port that has been used by a DatagramSocket sitting on the same machine? Why/why not?
  • Is it possible to create a MulticastSocket that listens and transmits on a UDP port that has been used by other MulticastSocket sitting on the same machine? Why/why not?
  • List the methods of MulticastSocket for joining and leaving a multicast group.
  • List the methods of MulticastSocket for dealing with TTL of packets.
  • Which type of exception may all the constructors of MulticastSocket throw?
  • List all the methods that add to MulticastSocket on top of DatagramSocket.

Reading

Thanks for Reading

If you would rather like to have this lecture note in printed format, please click the print action link in the top right corner.

If you find any problem in this lecture note, please feel free to tell Steven via steven@findaway.hk.

Edit - History - Print - Recent Changes - Search
Page last modified on November 12, 2009, at 02:07 PM