Networks and the web · A level · OCR H446 1.3.3, AQA 7517 4.9.3.1, Eduqas A500QS 2.2 · about 35 min
Receive a route as packets out of order, reject the damaged one, and drive it.
[1 mark]What does this program print?
def checksum(text):
return format(sum(ord(c) for c in text) % 256, '02X')
print(checksum('1/3:forward 30'))[1 mark]A receiver recalculates a packet's checksum and it does not match. What should it do?
[1 mark]Which error would the checksum 'sum of character codes modulo 256' fail to detect?
[1 mark]Why does the receiver send an ACK for packets that arrive intact?
[1 mark]Which layer of the TCP/IP stack numbers segments, acknowledges them and resends missing ones?
The robot starts facing forward. The Base sends a route of three packets in the format above, one every half second, out of order. One packet arrives damaged. When the Base hears NAK <number>, it sends that packet again.
1. Receive: check messages() every 0.1 s. For each packet, recalculate its checksum. If it matches, store the command under the packet's number and send ACK <number>. If it does not, print packet <number> corrupt and send NAK <number>. Keep going until you hold a good copy of every packet, as many as the total in the header says.
2. Act: for each number from 1 to the total, in order, print run: <command>, then drive it at speed 50. A command is a direction (forward, backward, left or right, where left and right slide sideways) and a whole number of centimetres.
3. Send DONE.
Do not drive until every packet is held, and read the route from the packets rather than typing it. If you act on the damaged packet, you will end up in the red zone.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
def checksum(text):
total = 0
for ch in text:
total = total + ord(ch)
return format(total % 256, "02X")
wait(3)
for sender, text in messages():
print(text)Plan your program here, then type it in and press Run.