1 |
h13 |
CS56 M16 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | section 9am or 10:30am |
||
Optional: name you wish to be called if different from name above. | ||||
Optional: name of "homework buddy" (leaving this blank signifies "I worked alone" |
h13: Threads and Sockets (Networking) (HFJ 15)
ready? | assigned | due | points |
---|---|---|---|
true | Tue 07/19 09:30AM | Thu 07/21 09:30AM |
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.
- (10 pts) 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 (either 9am or 10:30am) in the space indicated. If the other two items apply, please fill them in as well. Please do this every single time you submit homework for this class.
- What does it mean for a thread to be:
- (4 pts) new
- (4 pts) runnable
- (4 pts) running
- (4 pts) blocked
-
(3 pts) When you create a new thread which of these four states above does it go into? (circle one):
new runnable running blocked -
(3 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 - (4 pts) What puts a thread into the new state?
- (4 pts) What puts a thread into the runnable state?
- (4 pts) What puts a thread into the running state?
- Give two examples of events that can move a thread into a blocked state.
- (3 pts)
- (3 pts)
-
(10 pts) You are creating a socket by calling
new Socket("127.0.0.1",20000)
and you get aBindException
. 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.) - Briefly describe the role of each of these in setting up communication over the network between two running Java programs
- (5 pts) an IP address
- (5 pts) a port number
-
Suppose you need to choose a port number to listen for connections on.
- (5 pts) What is the range of numbers that you should always avoid?
- (5 pts) What is the highest number that a port number can possibly be?
-
(20 pts) Read in Chapter 15 about how you read data from a
Socket
and write data to aSocket
. Then, in the space below, write a classrawPrintFromCSWebserver
with amain
method that will:- connect to IP address 128.111.27.14 (www.cs.ucsb.edu) on port 80 (the web server port)
- send the following string over the connection:
"GET / \n"
(don’t include the quote marks) - read 20 lines of text, and print each of them out on
System.out
- close the connection
Suggestion: try to write this by hand first, then type it in on the system and test it out. You should get the first 20 lines that show up if you did a “view source” on the CS dept. home page. Note: if that IP address doesn’t work, type this at the Unix prompt and see what IP address comes up:
telnet www.cs.ucsb.edu 80
Use^]
(Ctrl-close-bracket) to get back to atelnet>
prompt, and typequit
to quit.