Docsity

Connection-Oriented Datagram Socket Using Code Sample Example4* java and Example5* java | CECS 327, Assignments of Computer Science

Toggle sidebar
bg1
CECS 327
Assignment 4 (10 points) โ€“ Due Tuesday, 3/3/09
This exercise guides you through experiments with connection-oriented datagram socket using
code sample Example4*.java and Example5*.java. You may download the example code from
the class website: http://www.cecs.csulb.edu/~jpark/cecs327/codeSample/Ch4/Example4-5/
a) Compile and run Example4*.java. Start the Acceptor first, then the Requestor. Sample
commands to do so are:
$ Java Example4ConnectionAcceptor 12345 Good-day!
$ Java Example4ConnectionRequestor localhost 12345
Describe and explain the outcome.
b) Re-run the applications โ€“ this time reverse the order of the steps (i) and (ii). Describe and
explain the outcome.
c) Add a time delay of 5 seconds (by using Thread.sleep( )) in ConnectionAcceptor just
before the message is written to the socket. This will have the effect of keeping the
Requestor blocked on reading for 5 extra seconds so that you can observe the
blocking visually. Do the diagnostic messages displayed on screen agree with the event
diagram in Figure 4.21?
d) Modify Example4*.java so that the ConnectionAcceptor uses 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.
e) Modify Example5*.java so that the ConnectionRequestor sends a replying message to
the ConnectionAcceptor after receiving a message from the Acceptor. The replying
message should be displayed by the Acceptor. Hand in an event diagram, the program
listings, and run outcome.

Partial preview of the text

Download Connection-Oriented Datagram Socket Using Code Sample Example4* java and Example5* java | CECS 327 and more Assignments Computer Science in PDF only on Docsity!

CECS 327

Assignment 4 (10 points) โ€“ Due Tuesday, 3 / 3 /0 9

This exercise guides you through experiments with connection-oriented datagram socket using code sample Example4.java and Example5.java. You may download the example code from the class website: http://www.cecs.csulb.edu/~jpark/cecs327/codeSample/Ch4/Example4-5/ a) Compile and run _Example4.java._ Start the Acceptor first, then the Requestor. Sample commands to do so are: $ Java Example4ConnectionAcceptor 12345 Good-day! $ Java Example4ConnectionRequestor localhost 12345 Describe and explain the outcome. b) Re-run the applications โ€“ this time reverse the order of the steps (i) and (ii). Describe and explain the outcome. c) Add a time delay of 5 seconds (by using Thread.sleep( )) in ConnectionAcceptor just before the message is written to the socket. This will have the effect of keeping the Requestor blocked on reading for 5 extra seconds so that you can observe the blocking visually. Do the diagnostic messages displayed on screen agree with the event diagram in Figure 4.21? d) Modify _Example4.java_ so that the ConnectionAcceptor uses 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. e) Modify _Example5.java_* so that the ConnectionRequestor sends a replying message to the ConnectionAcceptor after receiving a message from the Acceptor. The replying message should be displayed by the Acceptor. Hand in an event diagram, the program listings, and run outcome.