Quiz 2 -- CSCI 363

This is a closed book exam to be turned in at 1:30 pm. Name: _____________________.

Problem 1. 10 points

Give an example of how an IP number is written.

Problem 2. 30 points

Give short definitions of the following terms.

remote port





Problem 3. 15 points

Why are TCP servers almost always written with either child processes or multiple threads?

Problem 4. 5 points

Why would an method like the following one:

private static String unsignit(byte b) {
  if (b<0)
    return(Integer.toString((int)b+256)) ;
    return(Byte.toString(b)) ;

be useful in solving homework problem 2.

Problem 5. 15 points

Why is error handling usually more important in networking applications than in other applications?

Problem 6. 10 points

Here's a section of code from the textbook.

while (true) {
  theConnection = theServer.accept() ;
  p = new PrintStream(theConnection.getOutputStream()) ;
  p.println(new Date()) ;
  theConnection.close() ;

This loop is the body of a server for the daytime protocol which send the day-of-time to any client which connects to it. What does the call theServer.accept() do in this loop?

Problem 7. 15 points

Here's an almost complete client to connect to the daytime TCP server running on port 13 of penrose.cs.unca.edu. Two expressions, indicated by the big underlined blank areas, are missing. Fill them in.

import java.net.*;
import java.io.* ;
class GetTime{
  public static void main (String args[]) {
    Socket RemoteHostConnect ;
    BufferedReader RemoteInput ;
    try {
       Socket RemoteHostConnect = _____________________________________ ;
       BufferedReader RemoteInput  = new BufferedReader(
                           new InputStreamReader(
                                 RemoteHostConnect.getInputStream())) ;

       String TimeOfDay = _____________________________________________ ;
       System.out.println( TimeOfDay ) ;
    } catch ( IOException ioe ) {
       System.out.println("Oops") ;

If you can't remember the exact name of a method, write in something that is close.