The Internet and how data travels · 互联网与数据如何传输
The Internet
- The Internet is a huge network of computers that are joined together.
- No single computer is in charge. Many computers share the work.
- When you open a web page, your data travels across many of these computers.
互联网
- 互联网(Internet)是把许多计算机连接在一起的巨大网络。
- 没有任何一台计算机说了算。许多计算机一起分担工作。
- 当你打开一个网页时,你的数据会穿过许多这样的计算机。
Data is split into packets
- Big data does not travel in one piece.
- It is cut into small pieces called packets.
- Each packet carries a bit of the data, plus an address (where it goes) and a number (its order).
数据被切成数据包
- 大的数据不会一整块地传送。
- 它会被切成一小块一小块,叫作数据包(packet)。
- 每个数据包带着一小部分数据,加上一个地址(去哪里)和一个编号(它的顺序)。
Your message: "HELLO FRIEND"
Split into packets:
[1] "HELL" to: 203.0.113.7
[2] "O FR" to: 203.0.113.7
[3] "IEND" to: 203.0.113.7
Routing: many paths
- Routing means choosing a path for each packet through the network.
- Packets pass through many computers called routers on the way.
- Different packets can take different paths to the same place.
路由:多条路径
- 路由(routing)的意思是为每个数据包在网络中选择一条路径。
- 数据包在途中会经过许多叫作路由器(router)的计算机。
- 不同的数据包可以走不同的路径,去往同一个地方。
[You] --- router A --- router B --- [Website]
\ /
--- router C --- router D -
Packet 1 may go A -> B.
Packet 2 may go C -> D.
Both still arrive.
Redundancy and fault tolerance
- Redundancy means there is more than one path between two points.
- Because of this the Internet has fault tolerance: it keeps working even if one link fails.
- If router B breaks, packets just use another route, like C -> D.
冗余与容错
- 冗余(redundancy)的意思是两点之间不止有一条路径。
- 正因为这样,互联网才有容错能力:即使一条链路坏了,它仍然能工作。
- 如果路由器 B 坏了,数据包就改用另一条路线,比如 C -> D。
[You] --- router A --- (router B BROKEN)
\
--- router C --- router D --- [Website]
The path through B fails.
Packets still arrive through C -> D.
TCP/IP: the rules
- Computers must agree on rules so they can talk. We call a set of rules a protocol.
- IP (Internet Protocol) gives every computer an address and helps send each packet.
- TCP (Transmission Control Protocol) checks that all packets arrive and puts them back in order.
TCP/IP:规则
- 计算机之间必须商定规则才能交流。我们把一套规则叫作协议(protocol)。
- IP(网际协议)给每台计算机一个地址,并帮助发送每个数据包。
- TCP(传输控制协议)检查所有数据包是否都到达,并把它们重新按顺序排好。
Packets arrive (maybe out of order):
[3] "IEND" [1] "HELL" [2] "O FR"
TCP reorders them by number:
[1] "HELL" + [2] "O FR" + [3] "IEND"
= "HELLO FRIEND"
HTTP: the web
- The web (World Wide Web) is the pages and links you open in a browser.
- The web uses a protocol called HTTP (HyperText Transfer Protocol).
- Your browser sends an HTTP request ("please give me this page"); the server sends an HTTP response (the page).
HTTP:万维网
- 万维网(World Wide Web,简称 web)就是你在浏览器里打开的网页和链接。
- 万维网使用一种叫作 HTTP(超文本传输协议)的协议。
- 你的浏览器发出一个 HTTP 请求(“请把这个网页给我”);服务器送回一个 HTTP 响应(网页)。
Why this design is strong
- No single point controls everything, so there is no single point to break the whole Internet.
- Many paths + packets = the network can route around problems.
- Shared rules (TCP/IP, HTTP) let very different computers work together.
为什么这种设计很强大
- 没有任何一台计算机控制一切,所以没有单独一个点能让整个互联网瘫痪。
- 多条路径 + 数据包 = 网络可以绕过问题。
- 共同的规则(TCP/IP、HTTP)让差别很大的计算机也能一起工作。
Key words
- Packet: a small piece of data with an address and an order number.
- Routing: choosing a path for packets through routers.
- Redundancy / fault tolerance: many paths, so one failure does not stop the network.
- TCP/IP: rules to send packets and reassemble them in order.
- HTTP: the rules the web uses to request and send pages.
关键词
- 数据包(packet):一小块数据,带有地址和顺序编号。
- 路由(routing):为数据包在路由器之间选择路径。
- 冗余 / 容错:多条路径,所以一处故障不会让网络停止。
- TCP/IP:发送数据包并把它们按顺序重新组装的规则。
- HTTP:万维网用来请求和发送网页的规则。
Common mistakes
- Data is split into packets that travel separately and are reassembled.
- The Internet and the World Wide Web are not the same thing.
常见错误
- 数据被拆成数据包,分别传输后再重组。
- 互联网和万维网不是一回事。
Now you try
- These tasks model how data really travels: split it, reassemble it, and route around a failure.
- Press Check answer to test your code.
现在轮到你
- 下面的任务模拟数据真正的传输方式:把它切分、重新组装,以及绕过故障。
- 按检查答案来测试你的代码。
Data travels in packets · 数据以分组传输
The Internet splits data into packets that are routed and reassembled. · 互联网把数据拆成分组,分别路由后再重组。
TCP puts packets back in order by their number. packets is a list of [order, text] pairs that arrived shuffled. Write reassemble(packets) that sorts them by order and returns the joined text. Example: reassemble([[2, "O FR"], [1, "HELL"], [3, "IEND"]]) is "HELLO FRIEND". · TCP 会按数据包的编号把它们重新排好。packets 是乱序到达的 [编号, 文本] 对的列表。编写 reassemble(packets),按 order 排序并返回拼接后的文本。例如:reassemble([[2, "O FR"], [1, "HELL"], [3, "IEND"]]) 是 "HELLO FRIEND"。
Click Run to see the output here. · 点击“运行”查看此处输出。
Big data is cut into fixed-size packets. Write split(text, size) that returns a list of [order, chunk] pairs (order starts at 1), each chunk at most size characters. Example: split("HELLO FRIEND", 4) is [[1, "HELL"], [2, "O FR"], [3, "IEND"]]. · 大的数据会被切成固定大小的数据包。编写 split(text, size),返回 [编号, 片段] 对的列表(编号从 1 开始),每个片段最多 size 个字符。例如:split("HELLO FRIEND", 4) 是 [[1, "HELL"], [2, "O FR"], [3, "IEND"]]。
Click Run to see the output here. · 点击“运行”查看此处输出。
Redundancy gives more than one path, so the network can route around a failure. paths is a list of routes (each a list of router names). A route works only if it avoids the broken router. Write working_routes(paths, broken) returning the routes that do not · 不 contain broken. · 冗余提供了不止一条路径,所以网络可以绕过故障。paths 是若干路线的列表(每条路线是路由器名字的列表)。只有避开了 broken 路由器的路线才可用。编写 working_routes(paths, broken),返回不包含 broken 的那些路线。
Click Run to see the output here. · 点击“运行”查看此处输出。