Exam practice
Every question from the end of every unit, with hints and answers to open. After you check an answer, mark how you did, and come back to the ones you didn’t get.
15 questions
Unit 6 · Clients, Servers and the Web
Name the four layers of the TCP/IP model. For each, say what its header holds, and whether a router on the way reads it.
Answer
| Layer | Its header holds | Read by a router? |
|---|---|---|
| Application (HTTP, DNS…) | the app’s own message: method, path, headers | no |
| Transport (TCP, UDP) | the two port numbers; for TCP, sequence and acknowledgment numbers and a checksum | no (a home router doing NAT reads and changes the ports) |
| Internet (IP) | the two IP addresses, the TTL, which transport protocol is inside | yes: it chooses the next hop by the destination address and lowers the TTL |
| Link (Ethernet, Wi-Fi) | the MAC addresses of this one link, and a check at the end | yes: it takes it off and makes a new one for the next link |
Explain, with an example, why a server needs port numbers as well as an IP address. Why does a browser get a temporary port, while a web server uses 443?
Answer
An IP address only gets data to the right computer. A computer runs many programs that use the network, and the port number says which program the data is for: on one server, 443 for the web server, 22 for SSH, 25 for email.
A web server must listen on a port every client already knows, so it uses the well-known port for HTTPS, 443; a browser never has to be told. A client is never contacted first, so any free port will do: the operating system lends it a temporary one for each connection, which also makes each connection’s four numbers (both addresses, both ports) different, so two tabs on the same website are kept apart.
A message of 3,000 bytes is sent by TCP in segments of 1,000 bytes, starting at sequence number 801. The second segment is lost the first time. Write down, in order, each segment sent and each acknowledgment, until everything has arrived.
Hint
The segments are 801–1800, 1801–2800 and 2801–3800. An acknowledgment names the next byte wanted.
Answer
- Segment 801–1800 arrives → ACK 1801.
- Segment 1801–2800 is lost.
- Segment 2801–3800 arrives early: kept → ACK 1801 again (still waiting for 1801).
- No acknowledgment of 1801 comes before the sender’s timer runs out → segment 1801–2800 is sent again.
- It arrives; the receiver now has 801–3800 → ACK 3801.
The program at the receiving end gets all 3,000 bytes, in order, after step 5.
Compare TCP and UDP on four points. Which would you use for (i) sending a scanned marksheet, (ii) a live video lesson, (iii) a DNS question? Give reasons.
Answer
| TCP | UDP | |
|---|---|---|
| Connection | set up with a handshake | none |
| Delivery | reliable, in order (acknowledgments, retransmission) | best effort; pieces may be lost or out of order |
| Speed and delay | waits for lost pieces; slows down when the network is busy | never waits |
| Header | at least 20 bytes | 8 bytes |
- i.TCP: every byte of the file must arrive, or it is spoiled; a little delay doesn’t matter.
- ii.UDP: a piece of picture that arrives late is useless; it is better to carry on without it than to freeze.
- iii.UDP: the question and answer are tiny, and if either is lost the client simply asks again, with no handshake to wait for.
Explain how the internet differs from the old telephone network. Give two advantages of the internet’s way and one disadvantage.
Answer
The telephone network used circuit switching: before a call, a path through the exchanges was set up and reserved for that call until it ended. The internet uses packet switching: nothing is reserved; data goes in packets, each routed on its own, and every link carries everyone’s packets in turn. The telephone network kept its cleverness in the exchanges; the internet keeps it in the computers at the ends (the end-to-end principle).
Advantages: links are shared and used fully, with no capacity wasted on silences; if a router or link fails, packets go round it; new uses (the web, video calls) can be invented at the ends without changing the network.
Disadvantage: nothing is guaranteed, so when links are busy, packets are delayed or lost (which TCP has to repair, and which spoils live calls).
Read this request and answer the questions.
PUT /notices/12 HTTP/1.1Host: board.example.comContent-Type: application/jsonCookie: session=7Hq2… {"title": "Football match moved to Friday"}a. What does the client want done? b. What is the body, and what kind of data is it? c. Why is there a Cookie header? d. What status code would you expect if it works, if there is no notice 12, and if the session belongs to a student who may not edit notices?
Answer
- a.To replace notice 12 with the data sent (PUT: put this at that address).
- b.
{"title": "Football match moved to Friday"}, in JSON, as the Content-Type header says. - c.HTTP remembers nothing between requests, so the browser sends the session cookie with every request; the server looks it up to know who is asking.
- d.200 OK (or 204 No Content) if it works; 404 Not Found if there is no notice 12; 403 Forbidden for a signed-in student who isn’t allowed (401 would mean not signed in at all).
What does a website’s certificate contain? Describe the three checks a browser makes before it trusts one, and give one thing a valid certificate does not prove.
Answer
A certificate contains the names it is for (such as bhakaripay.com.np), the site’s public key, the dates it is valid from and to, who issued it, and that issuer’s digital signature over all of it.
The browser checks that: (1) the signatures lead, through any intermediates, to a root certificate authority in its own trusted list; (2) the certificate is for the very name in the address bar; (3) today is between its dates (and it hasn’t been withdrawn).
A valid certificate doesn’t prove that the site is honest or safe: anyone can buy a lookalike name, such as bhakaripay-reward.com, and get a valid certificate for it. It proves only that you reached the owner of the name in the address bar.
Write the Python dictionary below as JSON, then say what json.loads() would give back for each value: {"district": "Ilam", "tea": True, "elevation_m": (500, 3600), "notes": None}.
Answer
JSON: {"district": "Ilam", "tea": true, "elevation_m": [500, 3600], "notes": null}
Read back with json.loads(): "Ilam" a string; true → True; [500, 3600] → a list [500, 3600], not a tuple (JSON has no tuples); null → None. So the dictionary that comes back isn’t equal to the original, because of the tuple.
A shop’s website works out the total in the page’s JavaScript and sends {"item": "school bag", "price": 1800} to the server, which charges that price. Explain the flaw, how someone could use it, and how to fix it.
Answer
The server trusts a price the client sent. The browser belongs to the user: anyone can change the page’s JavaScript in the developer tools, or send their own POST request with "price": 1, and the server would charge Rs 1.
Fix: the client sends only what the customer chose ({"item": "school bag", "quantity": 1}); the server looks up the price in its own database and works out the total itself. The page may still show a total, for the customer’s convenience, but the server’s total is the one charged.
Draw a diagram of a web app that lets students of your school check the day’s notices on their phones. Show the hardware and the software at each part, the protocols and port numbers between them, and where the notices are stored. Mark where a check that “only teachers may post notices” must run, and explain why there.
Answer
The diagram should show: students’ phones (hardware) running a browser with the notices page (HTML, CSS, JavaScript); the internet (routers, DNS); a server computer in a data center or at the school (hardware) running an operating system, a web server program (HTTPS) and the app’s program (for example Python); and a database with the notices table, on the server’s disk. Links: HTTPS on port 443 between the phones and the web server; SQL between the app’s program and the database. A teacher’s laptop may be drawn too, as another client.
The check “only teachers may post notices” must run on the server, in the app’s program, on every request that posts a notice (by the session cookie: whose session is it, and is that person a teacher?). The page may hide the Post button from students, but anyone can send a POST request without the page, so only a check on the server protects the notices.
A program asks an API for data and gets no answer for a minute. Explain what a well-written client should do, and why it needs a timeout. Then give the right reaction to each of these answers: 200, 400, 401, 404, 429, 503.
Answer
Without a timeout, a client waits for ever for a server that will never answer, and the user sees a frozen app. A well-written client gives up after a set time (say 10 seconds), tells the user plainly that the server couldn’t be reached, and lets them try again (or tries again itself after a pause).
- 200: use the data.
- 400: the request was wrong: read the error message and fix what is sent (often, tell the user what to correct).
- 401: sign in first (or the session has run out), then try again.
- 404: there is nothing at that address: check the address or the id; don’t retry the same request.
- 429: too many requests: wait (the server may say how long) and send fewer.
- 503: the server is busy or down for now: try the same request again later, waiting a little longer each time.
a. Write the letter K (1001011 in 7-bit ASCII) as a byte with an even parity bit in front. b. It arrives as 11001001. What does the receiver find, and what does it do? c. Give an example of damage that the parity bit would miss, and say why TCP’s checksum and the link layer’s CRC are still needed.
Answer
- a.1001011 has four 1s, already even, so the parity bit is 0: 01001011.
- b.11001001 has four 1s: even, so the check passes, and the receiver accepts it. But compare it with what was sent: the first bit (the parity bit) and the seventh bit both flipped. Its data, 1001001, is the letter I, not K. Two flips cancel out in the count, so the damage isn’t noticed.
- c.Any even number of flipped bits, as in b. A parity bit catches only an odd number of flips, and only says that a byte is damaged, not which bit. TCP’s checksum, a 16-bit sum of the whole segment, catches every single flipped bit and most pairs; the CRC at the end of every frame is stronger still. Each layer’s check catches damage the others might miss, and a segment that fails is sent again.
A school library lends books. Each member (student_id, name, class) may borrow many books, and a book (book_id, title, author) is borrowed by many members over the years; each loan has a date out and a date back. a. Name the entities, with their attributes and primary keys. b. Describe the relationships, and resolve any many-to-many relationship. c. Describe the ER diagram you would draw in crow’s-foot notation, saying the marks at each end of each line.
Answer
- a.member (student_id PK, name, class); book (book_id PK, title, author); loan (loan_id PK, book_id FK, student_id FK, date_out, date_back).
- b.Member to book is many-to-many: a member borrows many books, and a book is borrowed by many members. It is resolved into the link entity loan, one row for each time one member borrows one book, with its own attributes, the dates. (Its key can’t be just (book_id, student_id), because the same member may borrow the same book twice; so loan gets its own key, loan_id, or the key (book_id, student_id, date_out).)
- c.Three boxes, each with its attributes, PK and FK marked. A line from member to loan: two bars next to member (each loan is for exactly one member), a ring and a fork next to loan (a member has zero or many loans). A line from book to loan, marked the same way: two bars next to book, a ring and a fork next to loan.
A bus company keeps this table of tickets: tickets (ticket_no, seat, travel_date, bus_no, route, driver, driver_phone, passenger_name, passenger_phone). Each bus always runs one route with one driver.
- a.Identify one update anomaly, one insertion anomaly and one deletion anomaly this table allows.
- b.Normalize it to third normal form. Write each table with its primary key, its foreign keys, and the normal form each step reaches.
- c.Explain how referential integrity protects the new design.
Answer
- a.Update: a driver’s phone number is written in every ticket for that bus; change it in some rows and not others, and the table gives two numbers. Insertion: a new bus, with its route and driver, can’t be recorded until someone buys a ticket for it. Deletion: deleting the only ticket ever sold for a bus loses which route it runs and who drives it.
- b.The table is in 1NF (one value per field, key ticket_no) and, with a single-column key, in 2NF. It isn’t in 3NF: route, driver and driver_phone depend on bus_no, and driver_phone on driver, none of which is the key (transitive dependencies). Each group of facts goes to the table of the thing it is about:
- drivers (driver_id PK, name, phone)
- buses (bus_no PK, route, driver_id FK → drivers)
- passengers (passenger_id PK, name, phone)
- tickets (ticket_no PK, bus_no FK → buses, travel_date, seat, passenger_id FK → passengers)
Each non-key field now gives a fact about its table’s key, the whole key and nothing but the key: 3NF. (The passenger needs some thought: the old table has no passenger ID and names aren’t unique, so its passenger_name and passenger_phone could be taken as facts about the ticket. Giving passengers a table of their own, with an ID, writes a regular passenger’s phone once. Drivers get an ID for the same reason.)
c. Every foreign key must point to a real row: the database refuses a ticket for a bus_no that isn’t in buses, and refuses to delete a bus, a driver or a passenger that tickets still point to. So the data can never contain a ticket on a bus that doesn’t exist.
a. Explain how CSMA/CA lets many phones share one Wi-Fi channel, and why a hostel’s Wi-Fi is slow when everyone is online in the evening, even if its internet connection is fast. b. Explain the difference between a static route and dynamic routing, and why the internet’s core can’t work with static routes alone.
Answer
a. Each phone listens before sending and waits while anyone else is sending. When the air is quiet, it waits a further random number of time slots, so phones waiting together rarely start together. It sends, and the access point answers each frame with an ACK. If no ACK comes, the frame was probably lost in a collision: the phone waits again, choosing from a range twice as long each time, and resends. RTS/CTS can book the air for a long frame, against hidden stations that can’t hear each other.
In the evening, many phones share one channel and, for the most part, only one can send at a time. More phones mean more waiting, more collisions (two choosing the same wait), longer waits after each one, and more frames sent twice. Phones with a weak signal send slowly and hold the air longer, and neighboring networks on the same channel share the same air. The bottleneck is the air around the access point, not the connection behind it.
b. A static route is typed into a router by hand and stays until someone changes it: enough for a home router with one way out. In dynamic routing, routers tell their neighbors which addresses they can reach, using a routing protocol (OSPF inside a network, BGP between networks), and build their tables from what they hear. The internet’s core has many thousands of routers and links that break and change every day; no one could update every table by hand, and only dynamic routing finds a way round a break within seconds or minutes.
