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...
An advantage of ____________________ is that multiple programmers can work on a large problem.
Fill in the blank(s) with the appropriate word(s).
You can customize the Quick Access Toolbar
Indicate whether the statement is true or false
What are the two goals of subnetting?
What will be an ideal response?
The Group Policy utility can be opened by typing what name into a Run box?
a. secpol.msc b. gpedit.msc c. grouppol.msc d. grppol.msc