TCP/IP和HTTP如何一起工作? [英] How do TCP/IP and HTTP work together?

查看:140
本文介绍了TCP/IP和HTTP如何一起工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与Wireshark一起调试我正在从事的一些物联网家庭自动化项目.我认为我将从更多了解HTTP和TCP/IP实际工作方式中受益.我发现的大多数解释都将HTTP描述为在TCP/IP之上",但是我要更具体地询问实际发送的内容.

I'm playing with Wireshark to debug some IoT home automation projects I'm working on. I think I'd benefit from understanding more about how HTTP and TCP/IP are actually working. Most explanations I'm finding describe HTTP as "riding on top of" TCP/IP, but I'm asking more specifically about what is actually being sent.

这是我捕获的客户端/服务器交互的一个示例:

Here's an example of a client/server interaction I captured:

Client: [SYN]
Server: [SYN, ACK]
Client: [ACK]

据我了解,他们现在已经成功建立了TCP连接.不过,下一个截图显示了我

If I understand so far, they've now successfully established a TCP connection. The next capture, though, shows me

Client: POST /whatever
Server: 200 OK

好吧,我迷路了.检查一下捕获结果,可以发现我在一帧中都具有一个以太网,IP,TCP和HTTP层.它实际上像客户端在TCP数据包结束后添加一堆文本并将这些多余的字节喷到路由器上一样简单吗?大概哪个然后解析出TCP/IP并相应地转发它?这是我困惑的根源. 从顶部开始"的意思是(从物理意义上来说)HTTP只是在TCP数据包之后在同一帧中发送的一系列字节?在这种情况下,HTTP是否被视为TCP/IP的有效负载?

Okay now I'm lost. Examining that capture shows me that I have an Ethernet, IP, TCP, and HTTP layer all in one frame. Is it actually as simple as the client adding a bunch of text after the TCP packet ends and squirting those extra bytes over to the router? Which, presumably, then parses the TCP/IP out and forwards it accordingly? This is the source of my confusion. By "rides on top of" is it meant (in a physical sense) that HTTP is just a series of bytes that are sent in the same frame, after the TCP packet? Is the HTTP in this case considered to be the payload of the TCP/IP?

当然要完成

Server: [FIN, ACK]
Client: [ACK]
Client: [FIN, ACK]
Server: [ACK]
//In this case the server terminates the connection.

下面的评论者提出了一个问题,使我感到好像不太清楚自己在问什么.

A commenter below asked a question which makes me feel as if I haven't been very clear about what I'm asking.

想象一下,我可以站在客户端和服务器之间(或者也许更精确地站在客户端和路由器之间,再站在路由器和服务器之间).忽略必须在物理介质上物理发送原始数据(校验和,纠错码等)的注意事项,相对于时间,实际流量将是什么样的?我会看到一个用于以太网层的字节,然后是一个用于ip层,tcp,http等的字节吗?

Imagine that I could stand between my client and the server (or perhaps it would be more accurate to stand between my client and the router and again between the router and the server). Ignoring the considerations when one has to physically send raw data over a physical medium (checksums, error correction codes, etc), what would the actual traffic look like, with respect to time? Would I see bytes for an ethernet layer followed by bytes for an ip layer, tcp, http, and so on?

推荐答案

网络层使用抽象和封装.较低的层封装较高的层.

The network layers use abstraction and encapsulation. The lower layers encapsulate the higher layers.

  • 应用程序层可以具有自己的协议,例如HTTP. HTTP 与目标设备上的HTTP通信,这是一个协议 传输应用程序数据(HTML).
  • 传输层(第4层)封装了应用程序数据报, 并与相同的传输层协议进行通信 目标设备.一些传输协议有保证并创造 连接的可靠性,例如TCP(段),但有些是 没有保证的无连接,例如UDP(数据报).目的 这一层的目的是将应用程序数据从一个应用程序 另一个应用程序.一些传输协议使用寻址(端口) 要做到这一点,有些人会使用其他东西,或者根本不使用.
  • 网络层将传输协议数据报封装到 数据包,并与目标设备网络协议进行通信. 该层的目的是从一个设备上获取数据包 网络连接到另一个网络上的设备.路由器使用寻址 数据包标头中的信息以完成此操作(IPv4,IPX, IPv6,AppleTalk等地址).
  • 数据链路层将网络数据包封装为帧,并且 它与同一网络上设备的数据链路通信. 该层的目的是将帧获取到另一台设备上 相同的网络(PC打印机,路由器等).一些数据链接协议 使用寻址(IEEE协议使用48位或80位MAC地址) 64位MAC地址),某些使用其他寻址(帧中继使用) DLCI,ATM使用VPI/VCI等),有些不使用编址(仅PPP) 有两个设备,因此不需要寻址).协议可以更改 封装的数据包从一个网络发送到另一个网络 在到达目标设备的途中.路由器剥去框架并 当他们将数据包从一个网络转发到另一个网络时,将其丢弃, 创建一个新框架来封装用于新网络的数据包.
  • 物理层(第1层)转换数据链路的帧 层(第2层)插入电线上的位".
  • The Application layer can have its own protocols, e.g. HTTP. HTTP communicates with HTTP on the target device, and it is a protocol that transfers the application data (HTML).
  • The Transport layer (layer 4) encapsulates the application datagrams, and it communicates with the same Transport layer protocol on the target device. Some transport protocols have guarantees and create connections for reliability, e.g. TCP (segments), but some are connectionless with no guarantees, e.g. UDP (datagrams). The purpose of this layer is to get the application data from one application to another application. Some transport protocols use addressing (ports) to accomplish this, and some use something else, or nothing at all.
  • The Network layer encapsulates the transport protocol datagrams into packets, and it communicates with the target device network protocol. The purpose of this layer is to get packets from a device on one network to a device on another network. Routers use the addressing information in the packet headers to accomplish this (IPv4, IPX, IPv6, AppleTalk, etc. addresses).
  • The Data Link layer encapsulates the network packets into frames, and it communicates with the data link of a device on the same network. The purpose of this layer is to get frames to another device on the same network (PC printer, router, etc.). Some data-link protocols use addressing (IEEE protocols use MAC addressing, either 48-bit or 64-bit MAC addresses), some use other addressing (frame relay uses DLCIs, ATM uses VPI/VCI, etc.), and some use no addressing (PPP only has two devices, so it needs no addressing). The protocol can change as the encapsulated packet is sent from one network to another on its way to the destination device. Routers strip off the frame and discard it as they forward the packets from one network to another, creating a new frame to encapsulate the packet for the new network.
  • The physical layer (layer 1) converts the frames of the Data Link layer (layer-2) into the "bits on the wire."

目标设备执行与上述操作相反的操作,将应用程序数据传递到目标应用程序.

The destination device performs the reverse of the above, delivering the application data to the destination application.

由于每一层的抽象和封装,您可以在不同的层混合和匹配不同的协议.例如,以太网可以承载任何数量的网络协议(IPv4,IPX,IPv6,AppleTalk等),而无需知道或关心以太网帧的有效载荷中的内容.相反,IP不知道或不在乎哪个数据链路协议(以太网,Wi-Fi,令牌环,PPP,帧中继等)承载它.

Because of the abstraction and encapsulation at each layer, you can mix and match different protocols at different layers. For example, ethernet can carry any number of network protocols (IPv4, IPX, IPv6, AppleTalk, etc.) without knowing or caring what is in the payload of the ethernet frame. Conversely, IP doesn't know or care which data-link protocol (ethernet, Wi-Fi, token ring, PPP, frame relay, etc.) is carrying it.

您的Web浏览器使用HTTP在HTTP与Web服务器之间传递数据(HTML). HTTP使用TCP将其传输到Web服务器. Web浏览器将请求TCP为其分配一个TCP地址(端口). Web服务器可能将众所周知的TCP端口80用于HTTP,TCP会将来自应用程序的数据流分段为TCP分段(不要将其与IPv4分段混淆). TCP将在Web服务器的OS上与TCP建立连接,TCP保证段将到达,并且提供给目标应用程序的数据将是完整的和有序的.

Your web browser uses HTTP to communicate the data (HTML) between it and the web server. HTTP uses TCP to transport it to the web server. The web browser will request that TCP assign it a TCP address (port). The web server likely uses the well-known TCP port 80 for HTTP, and TCP will segment the stream of data from the application into TCP segments (do not confuse this with IPv4 fragmentation). TCP will create a connection with TCP on the OS of the web server, and TCP guarantees that the segments will arrive, and that the data presented to the destination application will be complete, and in order.

理论上,TCP可以使用任何网络层协议,但实际上,它仅使用IPv4或IPv6. IP会将TCP段封装为IP数据包.

TCP can theoretically use any network-layer protocol, but in practice it only uses IPv4 or IPv6. IP will encapsulate the TCP segments into IP packets.

IP将使用该数据包将通过其发送的接口的数据链路协议.在PC上,这很可能是以太网或Wi-Fi,但也可以是PPP之类的东西.数据链路协议会将数据包封装为数据链路协议的帧.每个数据链路协议都有不同的帧格式.如果目标设备在同一网络上,则会对帧进行寻址并将其直接传送到目标.如果目标位于其他网络上,则将对这些帧进行寻址并将其传送到源OS中配置的网关(路由器).

IP will use the data-link protocol of the interface through which that packets will be sent. On a PC, this is most likely either ethernet or Wi-Fi, but it can be something else like PPP. The data-link protocol will encapsulate the packets into frames for the data-link protocol. Each data-link protocol has a different frame format. If the destination device is on the same network, the frames are addressed and delivered directly to the destination. If the destination is on a different network, the frames are addressed and delivered to the gateway (router) configured in the source OS.

接口将对帧中的位进行编码,并在接口的介质上对信号进行编码.

The interface will encode the bits in the frame and signal on the medium of the interface.

这篇关于TCP/IP和HTTP如何一起工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆