The transport layer resides between the application and Internet layers of the TCP/IP protocol stack. The TCP/IP Internet layer directs information to its destination. Still, it cannot guarantee that the information will arrive in the correct order, free of errors, or even that the information will arrive at all. The two most common transport layer protocols of the TCP/IP protocol suite are TCP and UDP. Both protocols manage the communication of multiple applications and provide communication services directly to the application process on the host.
傳輸層位於 TCP/IP 協定堆疊的應用層與網際網路層之間。TCP/IP 網際網路層負責將資訊導向其目的地,但無法保證資訊會依正確順序抵達、不含錯誤,甚至無法保證資訊一定會抵達。TCP/IP 協定套組中最常見的兩種傳輸層協定是 TCP 與 UDP。這兩種協定都負責管理多個應用程式的通訊,並直接為主機上的應用程式行程提供通訊服務。
The basic service that the transport layer provides is tracking communication between applications on the source and destination hosts. This service is called session multiplexing, and both UDP and TCP perform it. A major difference between TCP and UDP is that TCP can help ensure that the data is delivered, while UDP does not ensure delivery.
傳輸層提供的基本服務,是追蹤來源主機與目的主機上應用程式之間的通訊,此服務稱為工作階段多工(session multiplexing),UDP 與 TCP 都會執行此功能。TCP 與 UDP 的一個主要差異,在於 TCP 能協助確保資料送達,而 UDP 則不保證送達。
Multiple communications often occur at once; for instance, you may be searching the web and using FTP to transfer a file at the same time. The transport layer tracks these communications and keeps them separate. Both UDP and TCP provide this tracking. To pass data to the proper applications, the transport layer must identify the target application. If TCP is used, the transport layer has the additional responsibilities of establishing end-to-end connections, segmenting data and managing each piece, reassembling the segments into streams of application data, managing flow control, and applying reliability mechanisms.
多個通訊經常同時發生,例如你可能一邊瀏覽網頁,一邊用 FTP 傳輸檔案。傳輸層會追蹤這些通訊並將它們區隔開來,UDP 與 TCP 都提供此追蹤功能。為了將資料傳遞給正確的應用程式,傳輸層必須識別目標應用程式。若使用 TCP,傳輸層還須額外負責建立端對端連線、將資料分段並管理每個片段、將區段重組為應用程式資料串流、管理流量控制,以及套用可靠性機制。
Session Multiplexing
工作階段多工
Session multiplexing is how an IP host can support multiple sessions simultaneously and manage the individual traffic streams over a single link. A session is created when a source machine needs to send data to a destination machine. Most often, this process involves a reply, but a reply is not mandatory.
工作階段多工是指 IP 主機能同時支援多個工作階段,並在單一連線上管理個別的流量串流。當來源機器需要向目的機器傳送資料時,就會建立一個工作階段。多數情況下此過程會涉及回覆,但回覆並非必要。
Identifying the Applications
識別應用程式
To pass data to the proper applications, the transport layer must identify the target application. TCP/IP transport protocols use port numbers to accomplish this task. The connection is established from a source port to a destination port. Each application process that needs to access the network is assigned a unique port number in that host. The destination port number is used in the transport layer header to indicate which target application that piece of data is associated with. The sending host uses the source port to help keep track of existing data streams and new connections it initiates. The source and destination port numbers are not usually the same.
為了將資料傳遞給正確的應用程式,傳輸層必須識別目標應用程式。TCP/IP 傳輸協定使用連接埠號來完成此工作。連線是從來源連接埠建立到目的連接埠。每個需要存取網路的應用程式行程,在該主機上都會被指派一個唯一的連接埠號。目的連接埠號用於傳輸層標頭中,指出該筆資料所對應的目標應用程式。傳送端主機使用來源連接埠,協助追蹤現有的資料串流以及它所發起的新連線。來源與目的連接埠號通常不會相同。
Segmentation
分段
TCP takes variably sized data chunks from the application layer and prepares them for transport onto the network. The application relies on TCP to ensure that each chunk is broken up into smaller segments that will fit the maximum transmission unit (MTU) of the underlying network layers. UDP does not provide segmentation services. UDP instead expects the application process to perform any necessary segmentation and supply it with data chunks that do not exceed the MTU of lower layers.
TCP 會從應用層取得大小不一的資料區塊,並為其在網路上傳輸做準備。應用程式依賴 TCP 確保每個區塊被拆分成更小的區段,以符合底層網路層的最大傳輸單位(MTU)。UDP 不提供分段服務,UDP 反而期望應用程式行程自行執行必要的分段,並提供不超過底層 MTU 的資料區塊。
Flow Control
流量控制
If a sender transmits packets faster than the receiver can receive them, the receiver drops some of the packets and requires them to be retransmitted. TCP is responsible for detecting dropped packets and sending replacements. A high rate of retransmissions introduces latency in the communication channel. To reduce the impact of retransmission-related latency, flow control methods work to optimize the transfer rate and reduce the required retransmissions.
如果傳送端傳輸封包的速度快於接收端能接收的速度,接收端會捨棄部分封包並要求重新傳輸。TCP 負責偵測遺失的封包並傳送替代封包。較高的重傳率會在通訊通道中引入延遲。為降低重傳相關延遲的影響,流量控制方法會設法最佳化傳輸速率並減少所需的重傳次數。
Basic TCP flow control relies on acknowledgments that are generated by the receiver. The sender sends some data while waiting for an acknowledgment from the receiver before sending the next part. However, if the round-trip time (RTT) is significant, the overall transmission rate may slow to an unacceptable level. To increase network efficiency, a mechanism called windowing is combined with basic flow control. Windowing allows a receiving computer to advertise how much data it can receive before transmitting an acknowledgment to the sending computer.
基本的 TCP 流量控制依賴接收端產生的確認訊息。傳送端會傳送部分資料,並等待接收端的確認後才傳送下一部分。然而,如果往返時間(RTT)較長,整體傳輸速率可能會降到無法接受的程度。為了提升網路效率,會將稱為視窗化(windowing)的機制與基本流量控制結合使用。視窗化讓接收端電腦能夠在傳送確認給傳送端電腦之前,先宣告自己能接收多少資料。
Windowing enables the avoidance of congestion in the network.
視窗化能協助避免網路中的壅塞。
Connection-Oriented Transport Protocol
連線導向傳輸協定
A connection-oriented protocol establishes a session connection between two IP hosts within the transport layer and then maintains the connection during the entire transmission. When the transmission is complete, the session is terminated. TCP provides connection-oriented reliable transport for application data.
連線導向協定會在傳輸層內於兩個 IP 主機之間建立工作階段連線,並在整個傳輸過程中維持該連線。傳輸完成後,工作階段就會終止。TCP 為應用程式資料提供連線導向的可靠傳輸。
Reliability
可靠性
TCP reliability has these three main objectives:
TCP 可靠性有以下三個主要目標:
- Detection and retransmission of dropped packets偵測並重傳遺失的封包
- Detection and remediation of duplicate or out-of-order data偵測並修正重複或順序錯誤的資料
- Avoidance of congestion in the network避免網路中的壅塞


