Final Review Guide

Notes are allowed, as many as you want to create for this test (or other tests for other classes). Closed book, don't bring a bunch of stuff you downloaded.

Since the midterm, we've covered: Other content that should come back in some form:

Format

You can bring notes. As many notes as you want to create are allowed. But you can't bring the book, because you didn't write it as your test notes. You don't have to use microscopic font this way. Notes from other sources like Wikipedia aren't allowed.

Sample Questions

Here are a few things I think would be a decent question

Python section

This python program is supposed to receive two signed integers in big endian order, which should be 4 bytes each, and doesn't work.  What's wrong with it?

# Assume all needed includes are here
skt = socket(AF_INET, SOCK_STREAM)
skt.connect("the_server.com", 5000)

data =  skt.recv(4)
int_a, int_b = unpack("!ii", data)
print("int_a = ", int_a, "int_b", int_b)
	
Here's the server for the previous question.  It works, but only once, then the program stops.  Add a line so that it'll continue working for multiple clients (not at the same time).
# Assume all needed includes are here

skt = socket(AF_INET, SOCK_STREAM)
skt.bind(("0.0.0.0", 5000))
skt.listen(5)

cskt, caddr = skt.accept()
cskt.send(pack("!ii", 47, 352"))
cskt.close()
	
Here's the server for the first question.  It works, but the client always hangs.  Why's that?
# Assume all needed includes are here

skt = socket(AF_INET, SOCK_STREAM)
skt.bind(("0.0.0.0", 5000))
skt.listen(5)

while True:
	cskt, caddr = skt.accept()
	cskt.send(pack("!ii", 47, 352"))
cskt.close()
	
Here's a program that receives numbers from the server and adds them up.  But it doesn't print out the count at the end.  Why doesn't the total ever print out?
# Assume all includes are there
skt = socket(AF_INET, SOCK_STREAM)
skt.connect("the_server.com", 5000)

total = 0
while True:
	data =  skt.recv(4)
	int_a = unpack("!ii", data)[0]
	total = total + int_a

print("The total was:  ", total)

	
Note:  I don't think this is a good test question, but it was fun!
Suppose you have a friend who has a computer that they have left unlocked.  So you decide to run a program in the background!  Here's what you run:

def thread_starter():
	while True:
		start_new_thread(thread_starter, ())
thread_starter()

Will this use 100% CPU on all cores?
	
This python program is supposed to receive two signed integers in big endian order, which should be 4 bytes each.  Will this work?  Assume the only thing the server sends is the two integers.

# Assume all needed includes are here
skt = socket(AF_INET, SOCK_STREAM)
skt.connect("the_server.com", 5000)

data =  skt.recv(1024) # Think about what would happen if we added MSG_WAITALL
int_a, int_b = unpack("!ii", data)
print("int_a = ", int_a, "int_b", int_b)
	
This is NOT a question

# Assume all needed includes are here
skt = socket(AF_INET, SOCK_STREAM)
skt.connect("the_server.com", 5000)

data =  skt.recv(1024) 
int_a = unpack("!i", data)
if len(data) == 8:
	int_b = unpack_from("!i", 4, data)
else:
	data =  skt.recv(1024) 
	int_b = unpack("!i", data)

print("int_a = ", int_a, "int_b", int_b)