-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
### TCP 和 UDP 各自的优点 | ||
|
||
1.连接 | ||
|
||
TCP是⾯向连接的,在传输前需要三次握⼿建⽴连接,UDP不需要连接,即刻传输数据。 | ||
|
||
2、服务形式 | ||
|
||
TCP只能⼀对⼀,点对点服务,UDP⽀持⼀对⼀、⼀对多、多对多通信。 | ||
|
||
3、可靠性(传输的数据) | ||
|
||
TCP保证数据可靠交付,拥有**确认应答**和**重传机制**,⽆重复、不丢失、按序到达; | ||
|
||
UDP尽可能交付,不保证可靠性。 | ||
|
||
4、连接控制机制(传输路途) | ||
|
||
TCP拥有流量控制、拥塞控制,保证传输安全性等,UDP在⽹络拥堵情况下不会降低发送速率。 | ||
|
||
5、⾸部⼤⼩ | ||
|
||
TCP⾸部⻓度不使⽤选项字段是20字节,使⽤选项字段⻓度增加(可变) | ||
|
||
<font color='red'>8 位 = 1 字节</font> | ||
|
||
<img src="https://pic-1310558294.cos.ap-shanghai.myqcloud.com/img/202204240027703.png" alt="image-20220328231152943" style="zoom:33%;" /> | ||
|
||
UDP⾸部固定8字节。 | ||
|
||
<img src="https://pic-1310558294.cos.ap-shanghai.myqcloud.com/img/202204240027685.png" alt="image-20220328231247292" style="zoom:33%;" /> | ||
|
||
6、数据格式 | ||
|
||
TCP基于字节流,没有边界,但是保证传输顺序和可靠性; | ||
|
||
UDP继承了IP层特性,基于数据包,有边界可能出现乱序和丢包。 | ||
|
||
7、分⽚⽅式 | ||
|
||
TCP数据⼤于 MSS 时会在TCP层将数据进⾏分⽚传输,到达⽬的地后同样在传输层进⾏合并,如果有某个⽚丢失则只需要重传丢失的分⽚即可; | ||
|
||
UDP数据⼤于MTU时会在IP层分⽚,同样也在⽬的IP层合并,如果某个IP分⽚丢失,则需要将所有分⽚都进⾏重传,开销⼤。 | ||
|
||
8.应用场景 | ||
|
||
TCP:FTP 文件传输;Http/Https | ||
|
||
UDP:视频音频等多媒体通信;广播通知;包总量较少的通信,如 DNS ,SNMP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
TCP和UDP的首部如下: | ||
|
||
TCP⾸部⻓度不使⽤选项字段是20字节,使⽤选项字段⻓度增加(可变) | ||
|
||
<font color='red'>8 位 = 1 字节</font> | ||
|
||
<img src="https://pic-1310558294.cos.ap-shanghai.myqcloud.com/img/202204240027703.png" alt="image-20220328231152943" style="zoom:33%;" /> | ||
|
||
UDP⾸部固定8字节。 | ||
|
||
<img src="https://pic-1310558294.cos.ap-shanghai.myqcloud.com/img/202204240027685.png" alt="image-20220328231247292" style="zoom:33%;" /> |