Link Search Menu Expand Document

Homework 10: Networking

Homework Update

Run git pull to grab the latest homework.

Exercises

In today’s homework, we will be exploring TCP by using Python and netcat.

To explore this topic, we will be creating a waiting queue. The waiting queue should support operations below. For simplicity, you may assume that all names are 4 characters long, with no whitespaces, and there will never be more than 10 people in the queue.1 Skeleton code has been provided for you in server_skeleton.py. Rename this to server.py and implement according the follow specifications.

  1. GLI (short for “Get LIst”):
    • Returns full list of people on queue. For example, if the queue is ["LEVI", "EZRA"], LEVI EZRA should be sent.
  2. ADD NAME:
    • If NAME is not already on queue, add to queue at the back of the line. Then, send OK back. For example, if the queue is initially ["LEVI", "EZRA"], and we issue ADD OWEN, it should look like ["LEVI", "EZRA", "OWEN"]
    • Else, send ERROR back.
  3. AAP NAME POS (short for “Add At Position”):
    • If NAME is not already on queue, add to queue at position POS. (This can be done with the list.insert(pos, item) method.) Then, send OK back. For example, if the queue is initially ["LEVI", "EZRA"], and we issue ADD OWEN 0, it should look like ["OWEN", "LEVI", "EZRA"]. (In the case where POS > len(queue), add the person to the back of the queue. POS is guaranteed to be nonnegative.)
    • Else, send ERROR back.
  4. RMV NAME (short for “ReMoVe”):
    • If NAME is on the queue, remove them from the queue. Then, send OK back.
    • Else, send ERROR back.
  5. UPD NAME POS (short for “UPDate”):
    • If NAME is on the queue, change their position to POS. Then, send OK back.
    • Else, send ERROR back.
  6. GET NAME:
    • If NAME is on the queue, send back their position number.
    • Else, send ERROR back.
  7. EXT (short for “EXiT”): Ends the program. (Implemented for you.)

Hint: If the tests are infinite looping, you might not be handling a message correctly.

Submit server.py.

  1. Why do we do this, you ask? Remember the idea of packets? It turns out that TCP doesn’t guarantee that the full message is sent across the socket all at once, so it’s hard to know when the message is done sending. If we do this, we make our lives a bit easier in dealing with message length.