d. Based on Example1Sender.java, create a program Example1SenderReceiver.java which joins the multicast group, sends a message, then listens for (receives) a multicast message before closing the multicast socket and exiting. Compile the program, then start two or more Receiver processes before starting the SenderReceiver process. Describe the outcome. Turn in the listing of SenderReceiver.java.

This exercise is based on Example1 presented in this chapter



Both processes receive the message sent by the SenderReceiver – a process which has joined a multicast group receives the messages that it itself sends.


```
try {
// create the multicast socket
group = InetAddress.getByName("239.1.2.3");
s = new MulticastSocket(3456);

s.joinGroup(group);

s.setTimeToLive(32); // restrict multicast to processes
// running on hosts at the same site.
String msg = args[0];
DatagramPacket packet =
new DatagramPacket(msg.getBytes(), msg.length(),
group, 3456);
s.send(packet);
System.out.println("Waiting to receive");
byte[] buf = new byte[100];
// code added to receive a packet
DatagramPacket recv = new DatagramPacket(buf, buf.length);
s.receive(recv);
System.out.println(new String(buf));

s.close();
}
catch (Exception ex) { // here if an error has occurred
System.out.println("Problem: " + ex);
}

```

Computer Science & Information Technology

You might also like to view...

The SOFTWARE CROSS-REFERENCE REPORT lists all locations for each version of each software package.

What will be an ideal response?

Computer Science & Information Technology

Ad hoc mode is also known as _______________ mode.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Windows Classic Desktop applications can be written and executed using ____.

A. Windows Classic B. Windows 7, 8, or 10 C. Visual Studio D. Visual Basic

Computer Science & Information Technology

Give an INSERT statement that might cause a phantom.

Consider a schema with two tables, Table1 and Table2, each having three attributes, attr1, attr2, and attr3, and consider the statement

SELECT T1.attr1, T2.attr1
FROM Table1 T1, Table2 T2
WHERE T1.attr2 = T2.attr2 AND T1.attr3 = 5
AND T2.attr3 = 7

Computer Science & Information Technology