Modify Example4*.java so that the ConnectionAcceptoruses print( ) to write one character at a time to the socket before issuing a printlin( ) to write an end-of-line. Recompile and run the programs. Does the message still get received in its entirety? Explain.

This exercise guides you through experiments with connection-oriented datagram socket using code sample Example4.


The code change is as follows:
```
// create a PrinterWriter object for character-mode output
PrintWriter socketOutput =
new PrintWriter(new OutputStreamWriter(outStream));
// write a message into the data stream
for (int i=0; i socketOutput.print(message.substring(i, i+1));
socketOutput.println();

C:\tmp>Java Example4ConnectionAcceptor 12345 Good-day!
now ready accept a connection
connection accepted
message sent
data socket closed
connection socket closed

C:\tmp>Java Example4ConnectionRequestor localhost 12345
Connection request granted
waiting to read
Message received:
Good-day!
data socket closed
```

With stream-mode I/O, the data written into the stream and subsequently extracted from the stream is not synchronized, so that the granularity of the data can be of different size at the two ends. In this case, the acceptor writes one character at a time while the requestor blocks on reading a line of text – the blocking continues until the newline character is written into the socket by the acceptor.

Computer Science & Information Technology

You might also like to view...

The Command Bar in a folder window always shows the same choices no matter what function you are trying to perform

Indicate whether the statement is true or false

Computer Science & Information Technology

The images stored on microfilm and microfiche are so large that they can be read without a microfilm or microfiche reader.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

To publish Web pages, begin with a(n) _______________ document that you wish to share over the Internet.

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

Computer Science & Information Technology

Today's appliances are equipped with ___________________ computers.

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

Computer Science & Information Technology