Networks · GCSE · OCR J277 1.3.2, AQA 8525 3.5, Edexcel 1CP2 4.1.6 · about 15 min
Standards, and TCP, UDP, IP, HTTP, HTTPS, FTP, SMTP, POP and IMAP.
[1 mark]Which protocol sends email to a mail server?
[1 mark]Why is HTTPS used for logins and payments?
[1 mark]How is IMAP different from POP?
[1 mark]Why are standards needed?
[1 mark]Which protocol is used to transfer files between computers?
[1 mark]What does this program print?
reply = "404 Not Found"
code, rest = reply.split(" ", 1)
print(int(code) == 200, rest)False Not Found
404 is not 200; the rest is Not Found.
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.
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.