The worksheetDownload the PDF
Answers

F10.7 Protocols

Networks · GCSE · OCR J277 1.3.2, AQA 8525 3.5, Edexcel 1CP2 4.1.6 · about 15 min

BugBotLab

What this lesson is about

Standards, and TCP, UDP, IP, HTTP, HTTPS, FTP, SMTP, POP and IMAP.

Questions 6 marks in all

  1. [1 mark]Which protocol sends email to a mail server?

    1. ASMTP
    2. BIMAP
    3. CPOP
    4. DHTTP
    Answer: A. SMTP sends; POP and IMAP retrieve.
  2. [1 mark]Why is HTTPS used for logins and payments?

    1. AThe data is encrypted, so it cannot be read if intercepted
    2. BIt is faster than HTTP
    3. CIt compresses the page
    4. DIt stops the page loading twice
    Answer: A. The S is for secure.
  3. [1 mark]How is IMAP different from POP?

    1. AIMAP keeps email on the server so it stays in sync on every device
    2. BIMAP sends email; POP receives it
    3. CIMAP is for files; POP is for email
    4. DThere is no difference
    Answer: A. POP usually downloads and removes email from the server.
  4. [1 mark]Why are standards needed?

    1. ASo equipment and software from different makers work together
    2. BSo all devices are made by one company
    3. CSo networks are faster
    4. DSo data is encrypted
    Answer: A. A phone from one maker can use a router from another.
  5. [1 mark]Which protocol is used to transfer files between computers?

    1. AFTP
    2. BSMTP
    3. CIMAP
    4. DUDP
    Answer: A. File Transfer Protocol.
  6. [1 mark]What does this program print?

    reply = "404 Not Found"
    code, rest = reply.split(" ", 1)
    print(int(code) == 200, rest)
    Answer:
    False Not Found

    404 is not 200; the rest is Not Found.

The task: a tiny web client

Write request(path), which sends GET <path>, waits up to a second for the reply, and returns the status code as a number and the rest of the reply as text. Request /battery, /camera and /lights. For a status of 200, print <name>: <rest> (for example battery: 87, without the OK); otherwise print <name>: error <status>. Turn the LED green if the battery is above 50, and red if not.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

The hint students can ask for: Send the request and wait for the reply. The reply starts with the status number, so split it off the front and turn it into a number; what is left is the body. Choose what to print from the status.

A solution

from bugbot import *
connect()
def ask(question, seconds=1.0):
    send(question)
    for tick in range(int(seconds * 10)):
        wait(0.1)
        for sender, text in messages():
            return text
    return None

def request(path):
    reply = ask("GET " + path)
    code, rest = reply.split(" ", 1)
    return int(code), rest

battery = 0
for name in ["battery", "camera", "lights"]:
    status, rest = request("/" + name)
    if status == 200:
        value = rest.split(" ", 1)[1]
        print(f"{name}: {value}")
        if name == "battery":
            battery = int(value)
    else:
        print(f"{name}: error {status}")
if battery > 50:
    led(0, 255, 0)
else:
    led(255, 0, 0)

Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.