1
h08
CS56 F16
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu section
4pm, 5pm or 6pm
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

h08: Threads and Sockets (Networking) (HFJ 15) (Gradescope submission)

ready? assigned due points
true Mon 10/10 12:30PM Fri 10/14 08:00PM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the three lowest scores (if you have zeros, those are the three lowest scores.)


Please read HFJ Chapter 15, then answer these questions.

  1. (10 pts) This assignment should be submitted by scanning the pages in the correct order to a PDF file and uploading to https://gradescope.com.

    For more information, visit http://ucsb-cs56-pconrad.github.io and look for Gradescope: Student Self Submission under “topics”.

    Even though it is a Gradescope submission, nevertheless, please fill in the information at the top of this homework sheet, including your name and umail address. Put the time your discussion section starts (4pm, 5pm or 6pm) in the space indicated (the one you are registered for—even if you usually attend a different one.)

    If the other two items apply, please fill them in as well. Please do this every single time you submit homework for this class.

  2. (10 pts) You are creating a socket by calling new Socket("127.0.0.1",20000) and you get a BindException. What does this mean, and what should you do to try to fix this? (Hint: see the reading notes online at HFJ Chapter 15–linked to from the online version of this Homework assignment.)

  3. What does it mean for a thread to be:
    1. (4 pts) new
    2. (4 pts) runnable
    3. (4 pts) running
    4. (4 pts) blocked
  4. Briefly describe the role of each of these in setting up communication over the network between two running Java programs
    1. (5 pts) an IP address
    2. (5 pts) a port number
  5. (10 pts) What puts a thread into the new state?
  6. (10 pts) What puts a thread into the runnable state?
  7. (10 pts) What puts a thread into the running state?
  8. (4 pts) When you create a new thread which of these four states above does it go into? (circle one):

    new runnable running blocked
           
  9. (4 pts) When you call the .start() method of a thread, which of the four states above does it go into? (circle one):

    new runnable running blocked
           
  10. Give two examples of events that can move a thread into a blocked state.
    1. (3 pts)
    2. (3 pts)
  11. Suppose you need to choose a port number to listen for connections on.
    1. (5 pts) What is the range of numbers that you should always avoid?
    2. (5 pts) What is the highest number that a port number can possibly be?