首页 > 其他分享 >网络数据传输中的封装与解封装详解

网络数据传输中的封装与解封装详解

时间:2024-07-07 19:02:04浏览次数:8  
标签:layer 封装 数据包 packet will header 详解 数据传输 data

注:机翻,未校对。

The goal of networks is to transmit data from one host to another.
网络的目标是将数据从一个主机传输到另一个主机。

在这里插入图片描述

Encapsulation 封装

To achieve this goal, each layer adds its own header to the data. A header contains information specific for that layer, and it precedes the data itself.
为了实现此目标,每一层都会向数据添加自己的标头。标头包含特定于该层的信息,并且位于数据本身之前
在这里插入图片描述
Consider a case where we have a lookup service, used in order to find a person’s phone number, given the person’s name. The data consists of the person’s first and last name.
考虑一个案例,我们有一个查找服务,用于查找一个人的电话号码,给定这个人的名字。数据由此人的名字和姓氏组成。

Before the packet is sent, the fifth layer might add its own header, describing that this is a REQUEST packet. The header might also specify that this is a request to map from a person’s name to a phone number, and not vice versa.
在发送数据包之前,第五层可能会添加自己的标头,描述这是一个 REQUEST 数据包。标头还可以指定这是从人员姓名映射到电话号码的请求,反之亦然。

image-64

Header of the 5th layer, with data

Then, the fifth layer passes the data to the fourth layer. Note, that the fourth layer regards everything as data – ones and zeroes. It doesn’t care if the fifth layer added a header, or what is written inside that header.
然后,第五层将数据传递到第四层。请注意,第四层将所有内容视为数据——1 和 0。它不在乎第五层是否添加了标题,也不在乎该标题中写了什么。

The fourth layer then adds its own header. For instance, it might specify that the requested service is the names-and-phones service. It may also include a sequential number for the packet, so it can be identified later.
然后,第四层添加自己的标题。例如,它可能指定请求的服务是姓名和电话服务。它还可能包括数据包的序列号,以便以后可以识别。

image-65

Header of the 4th layer, with data which includes the 5th layer’s header

Afterwards, the fourth layer will pass the packet to the third layer. Again, the third layer will regard everything it has received – including the data itself, the header added by the fifth layer, and the header added by the fourth layer – simply as a chunk of data.
之后,第四层将数据包传递到第三层。同样,第三层将它收到的所有内容(包括数据本身、第五层添加的标头和第四层添加的标头)简单地视为数据块。

Then, the third layer will add its own header. For instance, it may include the source address and destination address of the packet.
然后,第三层将添加自己的标题。例如,它可能包括数据包的源地址和目标地址。

image-66

Header of the 4th layer, with data which includes the 4th layer’s header and data

This process goes on. So, each layer adds its own header to the packet*. This process is called encapsulation.*
这个过程还在继续。因此,每一层都会向数据包*添加自己的标头。此过程称为封装。

On the other end, the receiver gets the packet and needs to read and remove the headers.
在另一端,接收方获取数据包,需要读取和删除标头。

* The second layer may also include a trailer – an additional chunk of bits following the data, with some information.
* 第二层也可包括一个“尾部” —— 一组附加在数据后面的比特块,包含一些信息。

Putting it All Together 把它们放在一起

Now that we have covered the five layers, let’s have one example using all of them together.
现在我们已经介绍了这五个层,让我们举一个例子来同时使用它们。

在这里插入图片描述

Let’s say we would like to send a video file to our friend who lives in France, while we are enjoying a trip in Argentina. For that, we are using an email service.
假设我们想向住在法国的朋友发送一个视频文件,而我们正在阿根廷旅行。为此,我们正在使用电子邮件服务。

The fifth layer defines how the email will be transmitted. For example, it includes the email address of the sender, as well as the receiver. It contains a title, and the body of the message. It requires that we follow a specific template of an email address, that will be included in the header of this layer.
第五层定义了电子邮件的传输方式。例如,它包括发件人和收件人的电子邮件地址。它包含标题和邮件正文。它要求我们遵循电子邮件地址的特定模板,该模板将包含在此图层的标题中。

image-63

The five layers model, with an example of sending an email

Then, the fifth layer uses the fourth layer in order to split the email into chunks. Of course, each chunk will also carry the fourth layer’s header. It is also used in order to specify that we are currently using an email service.
然后,第五层使用第四层将电子邮件拆分为块。当然,每个块也将携带第四层的标题。它还用于指定我们当前正在使用电子邮件服务。

In this case, we definitely want the connection to be reliable – so the receiver will be able to play our video file correctly. Thus, the fourth layer will also handle reliability. On the receiver’s end, it might send an acknowledgment packet for every packet it receives.
在这种情况下,我们绝对希望连接可靠——这样接收器才能正确播放我们的视频文件。因此,第四层也将处理可靠性。在接收方端,它可能会为接收的每个数据包发送一个确认数据包。

The third layer will define the best route for every packet to be sent. It might choose different routes for different packets. Among other things, its header will contain the source and destination addresses for the packet.
第三层将为要发送的每个数据包定义最佳路由。它可能会为不同的数据包选择不同的路由。除其他事项外,其标头将包含数据包的源地址和目标地址。

The second layer will be responsible for every link between two directly connected devices. Its header will include the MAC addresses for each device.
第二层将负责两个直接连接的设备之间的每个链接。其标头将包括每个设备的 MAC 地址。

The first layer is responsible for encoding all the ones and zeros, and to pass them over the line. And then, decoding and reading those ones and zeroes on the other end. On this layer, we don’t really have a header, as it consists of single bits only.
第一层负责对所有 1 和 0 进行编码,并将它们传递到行上。然后,解码并读取另一端的 1 和 0。在这个层上,我们实际上没有标头,因为它只由单个位组成。
在这里插入图片描述

Summary 总结

This way, every layer uses the services provided by the lower layers, and the huge problem of transmitting data over the network becomes doable. How amazing is that?
这样一来,每一层都使用下层提供的服务,通过网络传输数据的巨大问题就变得可行了。


via: Omer Rosenbaum OCTOBER, 2022

标签:layer,封装,数据包,packet,will,header,详解,数据传输,data
From: https://blog.csdn.net/u013669912/article/details/140109049

相关文章

  • 反序列化POP链技术详解
    POP(ProcedureOrientedProgramming)链是反序列化安全问题中相对比较重要的技术点,相比于其他的反序列化问题,这种漏洞的产生更加难以发现,以及在利用上也比较复杂。要掌握这个东西首先要先了解面向对象中的几个特殊函数:1.__call()函数当调用一个不可访问的方法时会自动调用......
  • C语言下的文件详解
    主要内容文件概述文件指针文件的打开与关闭文件的读写文件    把输入和输出的数据以文件的形式保存在计算机的外存储器上,可以确保数据能随时使用,避免反复输入和读取数据 文件概述文件是指一组相关数据的有序集合文件是存储数据的基本单位,可以通过读取文件访问数......
  • CSS【详解】定位 position (静态定位 static -- 文档流排布 、相对定位 relative、绝对
    静态定位position:static【默认】此时,元素按文档流的方式排布:以左上角为起点内联元素从左到右依次排布,当一行排不下时,自动换到下一行继续从左到右排布块级元素独占一行此时,top、left、right、bottom、z-index等样式无效。相对定位position:relative相对......
  • Nuxt框架中内置组件详解及使用指南(二)
    title:Nuxt框架中内置组件详解及使用指南(二)date:2024/7/7updated:2024/7/7author:cmdragonexcerpt:摘要:“本文详细介绍了Nuxt3中和组件的使用方法,包括组件的基本概念、属性、自定义属性、获取引用以及完整示例,展示了如何在Nuxt项目中有效利用这两个组件。categories......
  • 掌握Java 8新特性:Lambda表达式与Stream API详解
    ......
  • 【数据分析】RFM会员价值度模型详解:大案例解析(第28天)
    系列文章目录RFM会员价值度模型分析用户行为分析文章目录系列文章目录前言1RFM会员价值度模型分析案例1.1RFM会员价值度模型概念1.2RFM会员价值度模型实现流程1.3RFM案例代码实现1.4数据可视化1.5案例结论1.6结果保存2用户行为分析案例2.1用户行为分析概念2......
  • STM32第十七课:连接云平台进行数据传输
    目录需求一、云平台项目创建二、代码编写1.导入MQTT包2.连接阿里云3.发布数据三、关键代码总结需求1.通过生活物联网平台设计一个空气质量检测仪app。2.连接阿里云平台将硬件数据传输到云端,使手机端能够实时收到。一、云平台项目创建先进入阿里云生活服务平台......
  • 运维锅总详解CPU
    本文从CPU简介、衡量CPU性能指标、单核及多核CPU工作流程、如何平衡CPU性能和防止CPU过载、为什么计算密集型任务要选择高频率CPU、超线程技术、CPU历史演进及摩尔定律等方面对CPU进行详细分析。希望对您有所帮助!一、CPU简介CPU(中央处理器)的主要功能是执行计算机程序中......
  • 51单片机:多功能时钟(附代码详解)
    一、基本功能介绍:1.时钟系统(TIME-24h)1.可根据当地时间自由修改!(非联网)按下按键S1                          默认时间05:12:01(小彩蛋*1)           使用定时器完成,保证在执行其他功能时,这套时钟......
  • 详解前缀码与前缀编码
    前缀编码是一种数据压缩技术,也被称为可变长度编码。它的基本原理是将频繁出现的字符或字符序列用较短的编码表示,而较少出现的字符或字符序列用较长的编码表示,从而达到压缩数据的目的。概念定义前缀码:给定一个编码序列的集合,若不存在一个序列是另一个序列的前缀,则该序列......