What is a network?
Why networks, LAN, WAN and PAN, client-server and peer-to-peer.
Do this lesson in the simulatorA network is two or more devices connected so they can share data. Your school's computers are a network, your phone joins one every time it connects to Wi-Fi, and the robots on the BugBot mat are a network too: every message one robot sends, the others receive. This module is about how networks work, from a single room to the whole internet.
Why connect computers?
| Advantages | Disadvantages |
|---|---|
| share files, printers and an internet connection | the hardware, such as cables and switches, costs money |
| people can communicate: email, messages, video calls | malware can spread from one computer to all the others |
| log in from any computer and find your own files | files can be attacked by hackers from outside |
| back up everyone's work from one place | if a central server fails, everyone is affected |
| install and update software on every computer at once | a large network needs specialist staff to manage it |
LAN, WAN and PAN
| LAN | WAN | |
|---|---|---|
| Stands for | local area network | wide area network |
| Covers | a small area: one building or site | a large area: a country, or the world |
| Hardware owned by | the organisation that uses it | usually rented from telecoms companies |
| Example | a school's network | a bank connecting its branches; the internet |
A WAN usually joins LANs together. The internet is the biggest WAN of all: a network of networks. A PAN, personal area network, is smaller still: the few devices around one person, such as a phone, earbuds and a smartwatch joined by Bluetooth.
Client-server and peer-to-peer
In a client-server network, one or more powerful computers called servers provide a service, and the other devices, the clients, ask them for it. A web server sends web pages; a file server stores everyone's work.
- Files and backups are kept in one place, and security is managed centrally.
- Servers are expensive, need specialist staff, and if one fails its clients cannot work.
In a peer-to-peer network, every device is equal. Each one shares its own files and resources directly with the others, with no server.
- Cheap and easy to set up; no single point of failure.
- Each device must be backed up and secured separately, and it gets hard to manage as it grows.
The robots on the mat are peers: no robot is in charge, and every robot hears every message.
Who is on the network?
Ask the other robots on the mat to say who they are. Each one replies when it hears the question:
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
send("who is on the network?")
for tick in range(15):
wait(0.1) # listen for 1.5 seconds
for sender, text in messages():
print(sender, "says:", text)
Task: roll call
Send who is on the network?. Listen for 1.5 seconds and, for each reply, print found <name> using the name the reply gives after here:. Then print devices on the network: <n>, counting the devices you found.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
Challenges
- Print the devices in alphabetical order.
- Ask twice, a second apart, and only count each device once.
- Is your school's network client-server or peer-to-peer? Give two pieces of evidence.