Protocols and the TCP/IP model · 协议与 TCP/IP 模型
| English | 中文 | Pinyin · 拼音 |
|---|---|---|
| protocol/ˈprəʊtəkɒl/ | 协议 | xié yì |
| TCP/ˌtiː siː ˈpiː/ | 传输控制协议 | chuán shū kòng zhì xié yì |
| UDP/ˌjuː diː ˈpiː/ | 用户数据报协议 | yòng hù shù jù bào xié yì |
| modularity/ˌmɒdjʊˈlærɪti/ | 模块化 | mó kuài huà |
| link layer/lɪŋk ˈleɪə/ | 链路层 | liàn lù céng |
| abstraction/əbˈstrækʃn/ | 抽象 | chōu xiàng |
| application layer/ˌæplɪˈkeɪʃn ˈleɪə/ | 应用层 | yìng yòng céng |
| transport layer/ˈtrænspɔːt ˈleɪə/ | 传输层 | chuán shū céng |
| port numbers/pɔːt ˈnʌmbəz/ | 端口号 | duān kǒu hào |
| internet layer/ˈɪntənet ˈleɪə/ | 网络层 | wǎng luò céng |
| packets/ˈpækɪts/ | 数据包 | shù jù bāo |
| IP address/ˌaɪ ˈpiː əˈdres/ | IP地址 | IP dì zhǐ |
| routers/ˈruːtəz/ | 路由器 | lù yóu qì |
| MAC addresses/mæk əˈdresɪz/ | MAC地址 | MAC dì zhǐ |
| connection-oriented/kəˈnekʃn ˈɔːrɪəntɪd/ | 面向连接 | miàn xiàng lián jiē |
| connectionless/kəˈnekʃənləs/ | 无连接 | wú lián jiē |
| layering/ˈleɪərɪŋ/ | 分层 | fēn céng |
The two-word message that started the internet
- On 29 October 1969 a student at UCLA typed the word LOGIN to a machine at Stanford, one letter at a time, with a colleague on the telephone confirming each one. After L and O the system crashed.
- The problem was never the wire. It was that two machines built by different companies had no agreed rules about what a byte meant, when to speak, or what to do when something was lost.
- Everything since has been the writing down of those rules. A protocol 协议 is that agreement, and the internet is a stack of them.
- This lesson is why protocols exist, why they are layered 分层, the four TCP/IP layers, and the difference between TCP and UDP.
开启互联网的那条两字消息
- 1969 年 10 月 29 日,加州大学洛杉矶分校的一名学生向斯坦福的一台机器逐个字母键入 LOGIN,同事在电话里逐个确认。打到 L 和 O 之后,系统崩溃了。
- 问题从来不是那根线。问题是两台由不同公司造的机器,对一个字节是什么意思、什么时候该说话、丢东西了该怎么办,没有约定的规则。
- 此后的一切,都是把那些规则写下来。协议(protocol)就是那份约定,而互联网是它们的一摞。
- 这一课讲协议为什么存在、为什么要分层(layering)、TCP/IP 的四层,以及 TCP 和 UDP 的区别。
What a protocol defines
- A protocol is a set of rules for how devices communicate. Both ends must follow the same rules, or one side's signals are meaningless to the other.
- It defines the format of the data, where the addresses sit and where the payload starts; the order of messages, who speaks first and when to acknowledge; the meaning of each message; the timing, timeouts and retransmissions; and what to do on an error.
- Without one, communication fails completely, the way two people with no shared language fail.
Rules agreed in advance, by both ends
协议规定什么
- 协议是设备之间怎样通信的一组规则。两端必须遵循同样的规则,否则一方的信号对另一方毫无意义。
- 它规定数据的格式——地址在哪里、有效载荷从哪里开始;消息的顺序——谁先说、何时确认;每条消息的含义;时序,超时和重传;以及出错时怎么办。
- 没有协议,通信彻底失败,就像两个没有共同语言的人。

事先约定好的规则,两端都遵守
A network protocol is: · 一个网络协议是:
A protocol defines the format, order, meaning, timing and error handling of messages — both ends must agree. · 一个协议定义消息的格式、顺序、含义、时序和错误处理——两端必须一致。
What does a protocol define? Select all · 所有 that apply. · 协议规定什么?选出所有适用的。
Format, order, meaning, timing and error handling. The cable's speed is a property of the hardware, not of the agreement. · 格式、顺序、含义、时序和错误处理。线缆速度是硬件的属性,不是这份约定的内容。
Why the protocols are layered
- Networking is too complex for one set of rules, so it is split into layers, each with one focused job, each talking only to the layer above and the layer below. The implementation is a stack.
- Modularity 模块化: one layer can be replaced without touching the others, so swapping Ethernet for Wi-Fi changes nothing above the link layer.
- Standardisation: equipment from different vendors interoperates because each layer's interface is agreed. Abstraction 抽象: a programmer writing a web app ignores everything the lower layers handle.
Four layers, each with one job
协议为什么要分层
- 网络太复杂,不能用一套规则,所以它被拆成层,每层只做一件事,只与上一层和下一层对话。实现方式是一个栈。
- 模块化(modularity):可以替换某一层而不动其他层,所以把以太网换成 Wi-Fi,链路层以上什么都不用变。
- 标准化:不同厂商的设备能互通,因为每层的接口是约定的。抽象(abstraction):写 Web 应用的程序员可以忽略下层处理的一切。

四层,每层一件事
A benefit of splitting networking into layers is: · 把网络拆成层的一个好处是:
Each layer has one job and a clear interface, so (e.g.) Ethernet can be swapped for Wi-Fi without touching higher layers. · 每层有一个工作和一个清晰的接口,所以(例如)以太网能被换成 Wi-Fi 而不触碰更高的层。
The four TCP/IP layers
| Layer | Purpose | Examples |
|---|---|---|
| application layer 应用层 | services for user programs, and the protocols they speak | HTTP, FTP, SMTP, IMAP |
| transport layer 传输层 | end-to-end delivery between processes, identified by port numbers 端口号 | TCP, UDP |
| internet layer 网络层 | carrying packets 数据包 between hosts by IP address IP地址, forwarded by routers 路由器 | IP |
| link layer 链路层 | sending bits over one physical link, framing with MAC addresses MAC地址 | Ethernet, Wi-Fi |
- The internet layer does not guarantee delivery. That is the transport layer's job, and only if TCP is used.
TCP/IP 的四层
| 层 | 用途 | 例子 |
|---|---|---|
| 应用层(application layer) | 为用户程序提供服务,以及它们使用的协议 | HTTP、FTP、SMTP、IMAP |
| 传输层(transport layer) | 进程之间的端到端传递,由端口号(port numbers)标识 | TCP、UDP |
| 网络层(internet layer) | 按 IP 地址(IP address)在主机之间传送数据包(packets),由路由器(routers)转发 | IP |
| 链路层(link layer) | 在一条物理链路上发送比特,用 MAC 地址(MAC addresses)封帧 | 以太网、Wi-Fi |
- 网络层不保证送达。那是传输层的工作,而且只在使用 TCP 时才有。
Tap the four layers of the TCP/IP model · 点击 TCP/IP 模型的四层
Explore each layer. Data travels DOWN the stack as it's sent (each layer adds its header) and back UP as it's received — and any layer can be swapped without touching the others. · 探索每一层。数据被发送时沿栈向下走(每层加上它的头),被接收时向上走——而任何一层都能被替换而不触碰其他的。
Match each TCP/IP layer to its job. · 把每个 TCP/IP 层与它的工作配对。
Application = user protocols; Transport = TCP/UDP delivery; Internet = IP routing; Link = bits on the medium. · 应用 = 用户协议;传输 = TCP/UDP 传递;网际 = IP 路由;链路 = 介质上的位。
The internet layer (IP) guarantees that every packet arrives. · 网络层(IP)保证每个数据包都到达。
IP forwards packets and does not guarantee delivery. Reliability is added above it, by TCP, and UDP deliberately does without it. · IP 只转发数据包,不保证送达。可靠性由它上面的 TCP 添加,而 UDP 有意不要它。
Worked example: a message crossing the internet
- Describe what happens at each layer when a browser requests a page from a server.
- Application: the browser builds an HTTP request for the page.
- Transport: TCP splits it into segments, adds the port numbers, and will acknowledge and retransmit anything lost.
- Internet: IP adds the source and destination IP addresses to each packet, and routers forward it hop by hop across networks.
- Link: each hop puts the packet in a frame with MAC addresses and sends the bits over the cable or radio. At the server the layers are unwrapped in reverse.
例题:一条消息穿越互联网
- 描述浏览器向服务器请求一个页面时,每一层发生了什么。
- 应用层:浏览器构造对该页面的 HTTP 请求。
- 传输层:TCP 把它切成报文段,加上端口号,并会确认和重传任何丢失的部分。
- 网络层:IP 给每个数据包加上源和目的 IP 地址,路由器逐跳把它跨网络转发。
- 链路层:每一跳把数据包放进带 MAC 地址的帧,把比特通过电缆或无线发出去。在服务器端,各层按相反顺序拆开。
Put the TCP/IP layers in order, from the user's program down to the wire. · 把 TCP/IP 各层按顺序排列,从用户程序向下到线缆。
Each layer wraps the one above; at the far end they are unwrapped in reverse order. · 每一层把上一层包起来;在对端按相反顺序拆开。
TCP and UDP
- TCP 传输控制协议 is connection-oriented 面向连接: it sets up a connection first, ensures all data arrives and in order, retransmits lost packets and controls flow. Reliable, at the cost of overhead and delay. Used by HTTP, HTTPS, SMTP and FTP.
- UDP 用户数据报协议 is connectionless 无连接: it sends and forgets, with no acknowledgements, no ordering and no retransmission. Low overhead, no guarantees.
- UDP is used for live streaming, DNS and online gaming, where speed beats reliability: a retransmitted video frame would arrive after the moment it was needed, so dropping it is better than waiting.
Guaranteed and slower, or fast and unguaranteed
TCP 与 UDP
- TCP(传输控制协议)是面向连接(connection-oriented)的:它先建立连接,确保所有数据都到达且有序,重传丢失的数据包并控制流量。可靠,代价是开销和延迟。HTTP、HTTPS、SMTP 和 FTP 都用它。
- UDP(用户数据报协议)是无连接(connectionless)的:发出去就不管了,没有确认、没有排序、没有重传。开销低,不作保证。
- UDP 用于直播流、DNS 和网络游戏,那里速度胜过可靠性:重传的视频帧会在需要它的时刻之后才到,所以丢掉它比等待更好。

有保证但更慢,或者快但无保证
How does TCP differ from UDP? · TCP 与 UDP 有什么不同?
TCP sets up a connection and ensures reliable, ordered delivery (with overhead); UDP is fire-and-forget. · TCP 建立一个连接并确保可靠、有序的传递(有开销);UDP 是发送即忘。
TCP is connection-oriented and guarantees ordered, complete delivery (with overhead), while UDP is fire-and-forget — faster but with no delivery guarantee. · TCP 是面向连接的,保证有序、完整的传递(有开销),而 UDP 是发送即忘——更快但没有传递保证。
That's why UDP suits live streaming, gaming and DNS, but TCP is used for files, email and secure web pages where every byte must arrive. · 这就是为什么 UDP 适合直播、游戏和 DNS,但 TCP 用于文件、邮件和安全网页,在那里每个字节都必须到达。
Live video streaming uses ____ because speed matters more than retransmitting lost packets. · 直播视频使用 ____,因为速度比重传丢失的数据包更重要。
A resent frame would arrive after the moment it was needed, so dropping it beats waiting. TCP's guarantees are worth their cost for a payment page. · 重传的帧会在需要它的时刻之后才到,所以丢掉它比等待更好。对支付页面来说,TCP 的保证值得它的代价。
Worked example: choose the transport protocol
- A company streams a live sports match and also sells tickets through a web page. Which transport protocol for each, and why?
- The live stream: UDP. A lost frame is worthless by the time it could be resent, so speed and low delay matter more than completeness, and the viewer would rather lose a frame than watch the picture stall.
- The ticket page: TCP. Every byte of the payment and booking must arrive, correct and in order, so the acknowledgements and retransmissions are worth their overhead.
- Name the protocol, then give the property of the data that decides it.
例题:选择传输协议
- 一家公司直播一场体育比赛,同时通过网页卖票。各用哪种传输协议,为什么?
- 直播流:UDP。丢失的一帧等到能重传时已经没有价值,所以速度和低延迟比完整性更重要,观众宁可丢一帧也不愿看画面卡住。
- 售票页面:TCP。支付和预订的每一个字节都必须正确、有序地到达,所以确认和重传的开销是值得的。
- 说出协议,再给出决定它的那条数据性质。
Marks that slip away
- A protocol is a set of rules, not a program or a cable. Name at least two of the things it defines.
- The benefit of layering is modularity, standardisation and abstraction, not "it is faster".
- IP does not guarantee delivery; TCP does. Do not credit the internet layer with reliability.
- UDP is not "worse". It is chosen where speed beats reliability, and the answer must say which kind of data that is.
容易丢掉的分
- 协议是一组规则,不是程序也不是线缆。至少说出它规定的两样东西。
- 分层的好处是模块化、标准化和抽象,不是"它更快"。
- IP 不保证送达;TCP 才保证。不要把可靠性算在网络层头上。
- UDP 不是"更差"。它被选用在速度胜过可靠性的地方,答案必须说清那是什么样的数据。
You've got it
- a protocol is agreed rules for format, order, meaning, timing and error handling, followed by both ends
- protocols form a stack of layers, giving modularity, standardisation and abstraction
- TCP/IP layers: application (HTTP, SMTP), transport (TCP, UDP, port numbers), internet (IP addresses, routers), link (Ethernet, Wi-Fi, MAC addresses)
- TCP is connection-oriented, ordered and reliable; UDP is connectionless with no guarantees, for streaming, DNS and gaming
你掌握了
- 协议是关于格式、顺序、含义、时序和错误处理的约定规则,两端都遵守
- 协议构成一摞层,带来模块化、标准化和抽象
- TCP/IP 四层:应用层(HTTP、SMTP)、传输层(TCP、UDP、端口号)、网络层(IP 地址、路由器)、链路层(以太网、Wi-Fi、MAC 地址)
- TCP 面向连接、有序、可靠;UDP 无连接、无保证,用于流媒体、DNS 和游戏