📚 TCP/IP Core Concepts for IB Computer Science | IB 计算机:TCP/IP 考点精讲
The TCP/IP protocol suite is the foundation of the modern Internet, enabling reliable communication across diverse networks. For IB Computer Science, understanding its layered architecture, core protocols, and mechanisms such as the three-way handshake is essential. This article provides a focused revision of key TCP/IP concepts, aligned with the IB syllabus.
TCP/IP 协议族是现代互联网的基础,使不同网络之间能够进行可靠通信。对于 IB 计算机科学来说,理解其分层架构、核心协议以及三次握手机制至关重要。本文紧扣 IB 大纲,对 TCP/IP 的核心考点进行精讲。
1. Introduction to the TCP/IP Model | TCP/IP 模型概述
The TCP/IP model defines a set of rules enabling hosts to communicate over a network. It is designed to be practical and implementation-oriented, developed alongside the evolution of the Internet. The model organises networking functions into four abstraction layers, from physical data transmission to user-facing applications.
TCP/IP 模型定义了主机间通过网络通信的规则。它与互联网的发展同步演进,注重实用性和可实现性。该模型将网络功能划分为四个抽象层,从物理数据传输到面向用户的应用程序。
Each layer provides services to the layer above it, creating a modular stack. This layering simplifies troubleshooting, protocol development, and interoperability. In IB exams, you are expected to name the layers, describe their roles, and place common protocols in the correct layer.
每一层都为其上一层提供服务,形成模块化堆栈。这种分层简化了故障排除、协议开发和互操作性。在 IB 考试中,要求你能够说出各层的名称、描述其作用,并将常见协议归到正确的层。
2. TCP/IP vs OSI Model | TCP/IP 与 OSI 模型的对比
The Open Systems Interconnection (OSI) model serves as a theoretical framework with seven layers, while TCP/IP is the practical implementation. Both models share the core idea of dividing communication tasks into layers, but they differ in the number of layers and some functional divisions.
开放系统互连(OSI)模型是一个具有七层的理论框架,而 TCP/IP 是实际应用的模型。两者都基于将通信任务分层的核心理念,但层数和部分功能划分有所不同。
The TCP/IP model combines OSI’s top three layers (Application, Presentation, Session) into a single Application layer, and its bottom two layers (Physical, Data Link) into the Network Access (or Link) layer. The Internet layer corresponds closely to OSI’s Network layer, and the Transport layer is identical in both models.
TCP/IP 模型将 OSI 的上三层(应用层、表示层、会话层)合并为一个应用层,将下两层(物理层、数据链路层)合并为网络接入层(或称链路层)。网际层大致对应 OSI 的网络层,传输层在两种模型中一致。
A common IB question asks you to compare the two models, highlighting that OSI is more detailed and academic, whereas TCP/IP is the standard used in real-world networking. Knowing both helps in understanding protocol functions and encapsulation.
IB 常见的考题要求对比这两种模型,指出 OSI 更详细且学术化,而 TCP/IP 是现实中网络通信的标准。理解二者有助于掌握协议功能和数据封装过程。
3. The Four Layers of TCP/IP | TCP/IP 的四层结构
The TCP/IP stack consists of four layers: Application, Transport, Internet, and Network Access (Link). Each layer has distinct responsibilities, and data passes through these layers during transmission, being encapsulated with headers at each step.
TCP/IP 协议栈包含四层:应用层、传输层、网际层和网络接入层(链路层)。每层职责明确,数据在传输过程中逐层向下传递,并在每一层添加头部进行封装。
- Application Layer: Supports end-user services like web browsing (HTTP), email (SMTP), file transfer (FTP), and domain name resolution (DNS).
应用层:支持终端用户服务,如网页浏览(HTTP)、电子邮件(SMTP)、文件传输(FTP)和域名解析(DNS)。 - Transport Layer: Provides host-to-host communication, reliability, and flow control using TCP or simple datagram delivery with UDP.
传输层:通过 TCP 提供主机到主机的可靠通信、流量控制,或使用 UDP 进行简单的数据报传输。 - Internet Layer: Handles logical addressing and routing of packets across networks. The core protocol is IP (Internet Protocol), along with ICMP and ARP.
网际层:负责数据包在跨网络中的逻辑寻址和路由。核心协议是 IP(网际协议),以及 ICMP 和 ARP。 - Network Access Layer: Deals with the physical transmission of data and hardware addressing (MAC). It includes Ethernet, Wi-Fi, and protocols for link control.
网络接入层:处理数据的物理传输和硬件寻址(MAC)。包括以太网、Wi-Fi 及链路控制协议。
In the IB syllabus, you need to be able to map protocols such as IP, TCP, UDP, HTTP, and FTP to their correct layers. A typical exam task is to state in which layer a given protocol operates.
在 IB 大纲中,你需要能够将 IP、TCP、UDP、HTTP、FTP 等协议对应到正确的层。常见的考题是指定某个协议在哪一层工作。
4. Application Layer: Protocols and Functions | 应用层:协议与功能
The Application layer provides the interface for user applications to access network services. It includes a wide variety of protocols, each designed for a specific task. IB students must recognise the most common ones and their roles.
应用层为用户应用程序访问网络服务提供接口。它包含多种协议,每种协议针对特定任务设计。IB 学生需要认识最常见的协议及其作用。
Key application-layer protocols and their default port numbers are summarised below:
下表汇总了关键的应用层协议及其默认端口号:
| Protocol | Port | Transport | Function |
|---|---|---|---|
| HTTP | 80 | TCP | Web page transfer (Hypertext Transfer Protocol) |
| HTTPS | 443 | TCP | Secure HTTP using TLS/SSL |
| SMTP | 25 | TCP | Sending email |
| POP3 | 110 | TCP | Receiving email |
| IMAP | 143 | TCP | Accessing email, keeping messages on server |
| FTP | 20/21 | TCP | File transfer |
| DNS | 53 | UDP (also TCP) | Domain name to IP resolution |
| DHCP | 67/68 | UDP | Dynamic assignment of IP addresses |
Understanding the port numbers and transport protocol associated with each service is a common examination focus. Note that DNS typically uses UDP for queries but can also use TCP for zone transfers.
掌握每个服务对应的端口号和传输协议是常见的考试重点。注意 DNS 通常使用 UDP 进行查询,但在区域传输时也可能使用 TCP。
5. Transport Layer: TCP and UDP | 传输层:TCP 与 UDP
The Transport layer is responsible for process-to-process delivery. It uses port numbers to direct data to the correct application. The two main protocols are TCP (Transmission Control Protocol) and UDP (User Datagram Protocol).
传输层负责进程到进程的传递。它利用端口号将数据导向正确的应用程序。两种主要协议是 TCP(传输控制协议)和 UDP(用户数据报协议)。
TCP provides reliable, connection-oriented communication. It ensures that data arrives intact, in sequence, and without duplicates, using acknowledgements, sequence numbers, and retransmission. TCP also implements flow control and congestion control.
TCP 提供可靠的、面向连接的通信。它通过确认、序列号和重传机制确保数据完整到达、有序且无重复。TCP 还实现了流量控制和拥塞控制。
UDP is a simple, connectionless protocol. It sends datagrams without establishing a connection, offering no guarantee of delivery or order. This makes it faster and suitable for real-time applications like streaming or VoIP, where occasional packet loss is acceptable.
UDP 是一种简单的、无连接的协议。它发送数据报时不建立连接,不保证数据的送达或顺序。这使它速度更快,适用于流媒体或网络语音等实时应用,这些应用可以容忍偶尔的数据包丢失。
IB candidates should be able to compare TCP and UDP in terms of reliability, overhead, ordering, and typical use cases. The choice between them depends on the application’s tolerance for latency and packet loss.
IB 考生应能从可靠性、开销、有序性和典型应用场景等方面对比 TCP 和 UDP。协议的选择取决于应用对延迟和丢包的容忍度。
6. TCP Connection Establishment: Three-Way Handshake | TCP 连接建立:三次握手
Before data can be exchanged, TCP establishes a virtual connection using a three-way handshake. This process synchronises sequence numbers and ensures both hosts are ready to communicate.
在交换数据之前,TCP 通过三次握手建立一个虚拟连接。这一过程同步序列号,并确保双方主机都已做好通信准备。
The handshake proceeds as follows:
1. Client sends a SYN (synchronise) segment with an initial sequence number x.
2. Server responds with a SYN-ACK, acknowledging x+1 and providing its own sequence number y.
3. Client sends an ACK confirming y+1. The connection is now established.
三次握手的过程如下:
1. 客户端发送一个带有初始序列号 x 的 SYN(同步)报文段。
2. 服务器回应 SYN-ACK,确认 x+1,并提供自己的序列号 y。
3. 客户端发送 ACK,确认 y+1。至此连接建立。
In IB exam questions, you may be asked to explain the purpose of each step or to analyse why a three-way handshake is necessary (to avoid old duplicate connections from causing confusion). The flags SYN and ACK are set in the TCP header to control this exchange.
在 IB 考题中,可能会问及每一步的目的,或分析为什么需要三次握手(以避免旧的重发连接请求造成混淆)。TCP 头部中的 SYN 和 ACK 标志位用于控制这一交换。
7. TCP Connection Termination: Four-Way Handshake | TCP 连接终止:四次挥手
TCP connections are full-duplex, meaning data can flow in both directions independently. Therefore, closing a connection requires a four-step termination process, often called the four-way handshake.
TCP 连接是全双工的,即数据可以同时在两个方向上独立传输。因此,关闭连接需要一个四步终止过程,通常称为四次挥手。
The steps are:
1. Host A sends a FIN segment to indicate it has finished sending data.
2. Host B replies with an ACK. At this point, A stops sending, but B may continue to send data.
3. When Host B has finished, it sends its own FIN.
4. Host A sends an ACK, and the connection is closed after a timeout.
步骤为:
1. 主机 A 发送 FIN 报文段,表示它已完成数据发送。
2. 主机 B 回应 ACK。此时 A 停止发送,但 B 仍可继续发送数据。
3. 主机 B 完成发送后,发送自己的 FIN。
4. 主机 A 发送 ACK,连接在超时后关闭。
IB questions may ask why four steps are needed compared to three for establishment. The answer lies in the need to close each direction of communication separately, preventing data loss during shutdown.
IB 考试中可能会问及为什么终止需要四步而建立只需三步。答案在于需要分别关闭两个方向的通信,以防止关闭过程中数据丢失。
8. Network Layer: IP Addressing and Routing | 网际层:IP 寻址与路由
The Internet layer, also known as the network layer, is responsible for logical addressing and routing data across different networks. The core protocol is IP (Internet Protocol), with IPv4 still dominant and IPv6 increasingly deployed.
网际层,也称网络层,负责逻辑寻址和跨网络路由数据。核心协议是 IP(网际协议),目前 IPv4 仍占主导,但 IPv6 正在加速部署。
An IPv4 address is 32 bits long, usually written in dotted-decimal notation (e.g., 192.168.1.1). It consists of a network portion and a host portion, determined by the subnet mask. IPv6 uses 128-bit addresses, written in hexadecimal, to solve address exhaustion.
IPv4 地址长度为 32 位,通常以点分十进制表示(如 192.168.1.1)。它由网络部分和主机部分组成,并由于子网掩码决定。IPv6 使用 128 位地址,以十六进制书写,以解决地址枯竭问题。
Routers operate at this layer, using routing tables and protocols such as OSPF and BGP to forward packets. The IP header includes source and destination addresses, Time to Live (TTL), and other fields essential for delivery.
路由器工作在这一层,使用路由表和 OSPF、BGP 等路由协议来转发数据包。IP 头部包含源地址、目的地址、生存时间(TTL)等关键字段,确保数据正确传递。
9. Subnetting and CIDR Notation | 子网划分与 CIDR 表示法
Subnetting divides a large network into smaller, manageable subnetworks, improving efficiency and security. A subnet mask determines which part of an IP address identifies the network and which part identifies the host.
子网划分将一个较大的网络分割成更小、更易于管理的子网,从而提高效率和安全性。子网掩码决定了 IP 地址的哪一部分标识网络,哪一部分标识主机。
With CIDR (Classless Inter-Domain Routing), the number of network bits is written after a slash, e.g., 192.168.1.0/24 indicates a subnet mask of 255.255.255.0, with 24 bits for the network portion. The number of usable host addresses is 2(32-n) – 2, where n is the prefix length.
采用 CIDR(无类别域间路由),网络位数写在斜线后,例如 192.168.1.0/24 表示子网掩码为 255.255.255.0,其中有 24 位用于网络部分。可用主机地址数为 2(32-n) – 2,其中 n 是前缀长度。
IB exam tasks often involve calculating the network address, broadcast address, and the range of valid hosts given an IP and subnet mask. Remember that the first address (all host bits 0) is the network address, and the last (all host bits 1) is the broadcast address.
IB 考试中常出现根据 IP 地址和子网掩码计算网络地址、广播地址和可用主机范围的题目。要记住,第一个地址(主机位全 0)是网络地址,最后一个地址(主机位全 1)是广播地址。
10. Ports, Sockets, and Multiplexing | 端口、套接字与多路复用
A socket is an endpoint for communication, defined by an IP address and a port number. It enables multiple applications on the same host to use network services simultaneously without confusion. The combination of source/destination IP addresses and port numbers uniquely identifies a connection.
套接字(Socket)是通信的端点,由 IP 地址和端口号定义。它使得同一主机上的多个应用程序可以同时使用网络服务而不会混淆。源/目的 IP 地址和端口号的组合唯一标识一个连接。
Ports are 16-bit numbers, divided into well-known (0–1023), registered (1024–49151), and dynamic/private (49152–65535). For example, a web server listens on port 80, and the client uses a dynamic port as its source port.
端口号为 16 位,分为知名端口(0–1023)、注册端口(1024–49151)和动态/私有端口(49152–65535)。例如,Web 服务器监听 80 端口,客户端使用一个动态端口作为源端口。
Multiplexing allows a transport layer protocol to handle data from multiple upper-layer applications by using different port numbers. TCP and UDP use socket pairs to demultiplex incoming segments to the correct application process.
多路复用使得传输层协议能够通过使用不同的端口号处理来自多个上层应用的数据。TCP 和 UDP 利用套接字对将传入的报文段解复用到正确的应用进程。
11. Data Encapsulation and Decapsulation | 数据封装与解封装
As data travels down the TCP/IP stack, each layer adds its own header (and sometimes a trailer) to the payload received from the layer above. This process is called encapsulation. On the receiving side, the headers are stripped in reverse order — decapsulation.
当数据沿 TCP/IP 协议栈向下传递时,每一层都会为来自上层的有效载荷添加自己的头部(有时还有尾部)。这个过程称为封装。在接收端,头部按照相反顺序被剥离——即解封装。
At the Application layer, the data is a message. The Transport layer adds TCP or UDP header, creating a segment. The Internet layer adds an IP header, forming a packet. Finally, the Network Access layer adds a frame header and trailer, producing a frame ready for transmission.
在应用层,数据是消息(message)。传输层添加 TCP 或 UDP 头部,形成报文段(segment)。网际层添加 IP 头部,形成数据包(packet)。最后,网络接入层添加帧头和帧尾,形成可以传输的帧(frame)。
IB questions frequently test knowledge of protocol data units (PDUs) at each layer: message at Application, segment at Transport, packet at Internet, and frame at Network Access. Understanding encapsulation explains how data remains intact and routable across heterogeneous networks.
IB 考试经常考查各层的协议数据单元(PDU):应用层为消息、传输层为报文段、网际层为数据包、网络接入层为帧。理解封装过程能解释数据如何在不同网络中保持完整并可路由。
12. Error Control and Flow Control in TCP | TCP 中的差错控制和流量控制
TCP includes robust mechanisms to ensure reliable data delivery. Error control is achieved through checksums, acknowledgements (ACKs), and automatic retransmission of lost or corrupted segments. Each segment carries a sequence number, allowing the receiver to reorder segments and detect duplicates.
TCP 包含了确保数据可靠传递的健壮机制。差错控制通过校验和、确认(ACK)以及对丢失或损坏报文段进行自动重传来实现。每个报文段携带一个序列号,使接收方能够重排报文段并检测重复。
Flow control prevents a fast sender from overwhelming a slow receiver. TCP uses a sliding window mechanism: the receiver advertises its available buffer space (window size), and the sender limits unacknowledged data to that amount.
流量控制可防止发送过快使接收方不堪重负。TCP 使用滑动窗口机制:接收方通告其可用缓冲区大小(窗口大小),发送方将未确认的数据量控制在该数值以内。
Congestion control is another critical function, where TCP senses network congestion through packet loss and dynamically adjusts the sending rate using algorithms like slow start, congestion avoidance, and fast recovery.
拥塞控制是另一项关键功能,TCP 通过丢包检测到网络拥塞,并使用慢启动、拥塞避免和快速恢复等算法动态调整发送速率。
These reliability features make TCP suitable for applications requiring accurate data delivery, such as file transfers, email, and web browsing. IB candidates should be able to explain the role of sequence numbers, ACK flags, and the sliding window.
这些可靠性特性使得 TCP 适用于需要精确数据传递的应用,如文件传输、电子邮件和网页浏览。IB 考生应能解释序列号、ACK 标志位以及滑动窗口的作用。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导