The internet, DNS and the cloud
The internet and the web, DNS, web servers and hosting, and the cloud.
Do this lesson in the simulatorThe internet is a worldwide network of networks, joined by routers. The World Wide Web is one service that runs on it: web pages, linked together and fetched with a browser. Email, video calls, online games and the BugBot lessons all use the internet too. This lesson follows what happens when you type a web address, and looks at hosting and the cloud.
DNS: names to addresses
Routers deliver packets using IP addresses, but people remember names like www.bugbotlab.com. The Domain Name System (DNS) turns names into IP addresses:
- You type a web address, a URL, into the browser.
- The browser asks a DNS server for the IP address of that domain name.
- The DNS server looks the name up. If it does not know it, it asks other DNS servers.
- It sends the IP address back to the browser.
- The browser sends its request to the web server at that IP address.
Without DNS, you would need to remember a number for every website.
Web servers and clients
A web server stores websites and sends pages to clients when they ask. A web browser is the client: it requests pages, receives them, and displays them. This is client-server, from lesson F10.1.
Hosting means storing a website on a server that is always connected to the internet, usually rented from a hosting company, so anyone can reach it at any time.
The cloud
The cloud means using remote servers over the internet to store files, run software, or do processing, instead of your own computer. The lesson you are reading comes from the cloud, and so does your saved work.
| Advantages | Disadvantages |
|---|---|
| reach files and software from any device, anywhere | needs an internet connection |
| no need to buy and look after your own servers | ongoing cost, often a subscription |
| storage and processing can grow as needed | data is held by another company, maybe in another country |
| the provider handles backups and security updates | if the provider has an outage, you cannot work |
A DNS server on the mat
The robots on this mat have addresses, and a DNS robot knows them. Ask it for the address of scout.bot:
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
send("lookup scout.bot")
for tick in range(10):
wait(0.1)
for sender, text in messages():
print(sender, "says:", text)
Messages on the mat are addressed as to <address>: <message>. Only the robot with that address answers.
Task: look it up
Two robots are on the mat: scout.bot and rover.bot. Look up scout.bot with the DNS robot, then take the IP address from its reply. Send to <address>: where and the Scout answers at <x>,<y>. Drive to about 13 cm in front of it, into the green square, without touching anything. The helpers ask, numbers_in, go_to and near are ready to use.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
import math
def ask(question, seconds=1.0):
# send a question and return the first reply that arrives within `seconds`, or None
send(question)
for tick in range(int(seconds * 10)):
wait(0.1)
for sender, text in messages():
return text
return None
def numbers_in(text):
# every number in a message, as floats: "at 25,55" -> [25.0, 55.0]
out = []
for word in text.replace(",", " ").split():
try:
out.append(float(word))
except ValueError:
pass
return out
def wrapped(h):
return (h + 180) % 360 - 180
def go_to(x, y, speed=60):
# one step of driving towards (x, y), measured from the start; call it in a loop
px, py = position()
a = math.radians(wrapped(math.degrees(math.atan2(x - px, y - py)) - heading()))
drive(speed * math.cos(a), speed * math.sin(a), wrapped(0 - heading()) * 3)
def near(x, y, cm=4):
px, py = position()
return math.hypot(x - px, y - py) < cm
Challenges
- Keep a DNS cache: a dictionary of names you have already looked up, so you only ask once.
- Look up
rover.bottoo, and print both robots' positions. - Why does a DNS server ask other DNS servers rather than knowing every name itself?