CSS 503
Lab Work 4: UDP Multicast
Professor: Munehiro Fukuda
Lab work date: See the syllabus
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. |
#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 lab4Complete 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!