CSS 503
Lab Work 4: UDP Multicast

Professor: Munehiro Fukuda
Lab work date: See the syllabus


1. Purpose

This laboratory work intends to familiarize you with UDP multicast. You will code a simple client-server program that multicasts a given message from a single client to multiple servers.

2. UDP Multicast Class

You will use ~css503/programming/lab4/UdpMulticast.h and UdpMulticast.cpp.
Methods Descriptions
UdpSocket( char group[], int port ) A default constructor that opens a UDP datagram socket and has it participate in a given group address, (e.g. "238.255.255.255") at a given port.
~UdpSocket( ) A default dstructor that closes the UDP socket.
int getClientSocket( ) uses this socket descriptor as a client multicast socket. It returns a socket descriptor but you do not directly use the descriptor.
int getServerSocket( ) uses this socket descriptor as a server multicast socket. It returns a socket descriptor but you do not directly use the descriptor.
bool multicast( char buf[] ) has a client multicast a give message in buf[] to all servers belonging to the same group@port. It returns true upon a success, otherwise false.
recv( char buf[], int size ) has a server receive a multicast message into a given buf[] with the size. It returns true upon a success, otherwise false.

3. Statement of Work

The following code is a template for launching a UDP Multicast client and a server. It reads three arguments: a group address (e.g., 238.255.255.255) in argv[0], a port (e.g., 5001) in argv[1], and a message in argv[2]. If a message is not given, the program behaves as a server, otherwise as a client.
   #include "UdpMulticast.h" // UdpMulticast                                                           
   #include <iostream>       // cerr                                                                   

   #define SIZE 1024         // buffer[SIZE]                                                           

   using namespace std;

   int main( int argc, char *argv[] ) {
     // validate arguments                                                                             
     if ( argc < 3 ) {
       cerr << "usage: lab4 group port [message]" << endl;
       return -1;
     }
     char *group = argv[1];
     int port = atoi( argv[2] );
     if ( port < 5001 ) {
       cerr << "usage: lab4 group port [message]" << endl;
       return -1;
     }
     char *message = ( argc == 4 ) ? argv[3] : NULL;

     // if message is null, the program should behave as a server,
     // otherwise as a client.     

     return 0;
   }
Compile the program as follows:
   css503@uw1-320-18 lab4]$ g++ lab4.cpp UdpMulticast.cpp -o lab4
Complete the main() function so that the program runs as follows:
   [css503@uw1-320-18 lab4]$ ./lab4 238.255.255.255 5001 Hello!
   [css503@uw1-320-18 lab4]$ ./lab4 238.255.255.255 5001 Bye!
   [css503@uw1-320-18 lab4]$ 

   [css503@uw1-320-19 lab4]$ ./lab4 238.255.255.255 5001
   Hello!
   Bye!

   [css503@uw1-320-20 lab4]$ mv a.out lab4
   [css503@uw1-320-20 lab4]$ ./lab4 238.255.255.255 5001
   Hello!
   Bye!

4. What to Turn in

Turn in the following materials at the end of class:
  1. Your lab4.cpp
  2. Your execution output
If your time runs out, you may submit it together with programming assignment 4.