Homework 5 Protocol corrections/questions
| s.start_timer(r.seq);
event = r.wait_for_event(); |
| r.start_timer(r.seq);
event = r.wait_for_event(); |
Often simplest to use buffered input. BufferedReader class for input supports input of a complete string or individual characters and has the following useful characteristics:
Read a line of text. A line is considered to
be terminated by any one of a line feed ('\n'), a carriage return ('\r'),
or a
carriage return followed immediately by a
linefeed.
Returns:
A String containing
the contents of the line, not including any line-termination characters,
or null if the end of
the stream has
been reached
Socket s = connection.accept(); // Wait for connection
BufferedReader in = new BufferedReader( // Socket input
new InputStreamReader( s.getInputStream() ) );
while( (from=in.readLine()) != null && !from.equals("")) {
System.out.println( from );
}
|