Modify the original Example1 code so that the receiver loops indefinitely to receive and output datagrams. Recompile. Then (i) start the receiver, (ii) execute the sender, sending a message “message 1”, (iii) in another window, start another instance of the sender, sending a message “message 2”. Does the receiver receive both messages? Capture the output. Draw a picture to describe the IPC involved in the experiment.
This exercise guides you through experiments with connectionless datagram socket via code sample Example1. As a start, it is recommended that you run both programs on one machine, the host name of which you may refer to as “localhost”, as in the command “java Example1Sender localhost 12345 hello” to execute Example1Sender. You may optionally repeat the exercises by running the programs on separate machines, assuming that you have access to such machines.
The receiver, using the same socket, does receive both messages even though they came from different processes.
The code change in the receiver:
```
try {
DatagramSocket mySocket = new DatagramSocket(port);
while (true) {
// instantiates a datagram socket for receiving the data
byte[ ] buffer = new byte[MAX_LEN];
DatagramPacket datagram =
new DatagramPacket(buffer, MAX_LEN);
mySocket.receive(datagram);
String message = new String(buffer);
System.out.println(message);
} //end while
} // end try
```
The output:
The IPC diagram:
Computer Science & Information Technology
You might also like to view...
You can examine all of the changes and comments in the document one at a time
Indicate whether the statement is true or false
For each donation received, ____ charges a percentage for providing the service of enabling donors to give to charitable organizations online and for processing the associated credit card transaction.
A. Facebook B. Network for Good C. Global Warming D. LinkedIn