# 5.1 传输层提供的服务

{% hint style="success" %}
传输层是只有主机才有的层次，即进程和进程之间的通信，也称端到端通信
{% endhint %}

## 5.1.1 传输层的功能

* 传输层提供进程和进程之间的逻辑通信
* 复用和分用
* 传输层对收到的报文进行差错检测
* 传输层的两种协议
  * TCP
    * 可靠
    * 面向连接
    * 时延大
    * 适用 于大文件
  * UDP
    * 不可靠
    * 无连接
    * 时延小
    * 适用 于小文件

## 5.1.2 传输层的寻址与端口

**复用**：应用层所有的应用进程都可以通过传输层再传输到网络层

**分用**：传输层从网络层收到数据后交付指明的应用进程

**端口**（逻辑端口/软件端口）：是传输层的SAP，唯一标识主机中的应用进程

* 端口号**只有本地意义**，在因特网中不同计算机的相同端口是没有联系的
* 端口号长度为16bit，能表示65536个不同的端口号
  * **服务端使用的端口号**
    * **熟知端口号**（0\~1023）：给TCP/IP最重要的一些应用 程序，所有用户都知道
    * **登记端口号**（1024\~49151）：为没有熟知端口号的应用程序使用的，使用时登记
  * **客户端使用的端口号**（49152\~65535）：仅在客户进程运行时才动态选择

### 1、常见端口号

|  应用程序  | 端口号 |
| :----: | :-: |
|   FTP  |  21 |
| TELNET |  23 |
|  SMTP  |  25 |
|   DNS  |  53 |
|  TFTP  |  69 |
|  HTTP  |  80 |
|  SNMP  | 161 |

### 2、套接字

套接字：<mark style="color:blue;">**主机号**</mark>+<mark style="color:red;">**端口号**</mark>

在网络中采用发送方和接收方的套接字组合来识别端点，套接字<mark style="color:orange;">**唯一标识**</mark>了网络中的一个<mark style="color:blue;">**主机**</mark>（主机号）和它上面的一个<mark style="color:red;">**进程**</mark>（端口号）。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aye10032.gitbook.io/computernetwork/di-wu-zhang-chuan-shu-ceng/5.1-chuan-shu-ceng-ti-gong-de-fu-wu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
