TCP 与 UDP - 什么是 TCP 连接?
TCP 连接到底是什么? 据我所知,客户端到服务器之间没有物理连接。此连接是否只是客户端的套接字与服务器在三次握手后创建的新套接字链接? 此后,一旦建立“连接”,连接两端的套接字就知道将其数据包发送到哪里。
除了与 TCP 的初始握手之外,这与 UDP 的工作方式有何不同? 每个服务器套接字是否只有一个客户端向该特定套接字发送数据包?
在主机之间建立专用连接有哪些可能的优点?我对 TCP 和 UDP 的理解还很基础,所以广泛的概括应该就足够了。
What exactly is a TCP connection?
I understand there isn't a physical connection from the client to server. Is this connection just the client's socket being linked with the new socket created by the server after the three-way-handshake?
Thereafter once the "connection" is set up, the sockets on either ends of the connection then know where to send their packets.
How does this differ from the way UDP functions other than the initial handshake with TCP?
Is it that each server socket only has one client that sends packets to that particular socket?
What are some possible advantages of having a dedicated connection between hosts? My understanding of TCP and UDP is still very basic, so broad generalizations should suffice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让我们把它分成几部分。首先,网络基于IP,这是一种为每个网络节点分配地址的协议,它允许您发送少量数据(通常最多64kB,但通常只有1500B) )从一个节点到另一个节点。
这本身还没有多大价值,因为我们无法检查数据是否实际到达以及是否以正确的顺序到达。如果我们想要一个抽象机制来传输任意数量的数据并确保它们到达,我们需要网络顶部的另一个协议来处理这种“传输”。这就是 TCP 的目的。
然而,与 TCP 并行的还有另一种“传输”协议,它根本不做任何检查并且没有可靠性,即 UDP。 UDP 只是原始 IP 数据包的薄包装,它添加了一点元数据(例如端口号)。
不过,UDP 仍然有用,因为在许多情况下,数据完整性已经移交给更高的协议,因此不需要复杂的传输协议。例如,这用于虚拟网络服务,其中 TCP/IP 的另一个实例通常在 UDP 通道上运行。 (在这种情况下,由于重发级联,使通道使用像 TCP 这样的可靠协议实际上可能会产生灾难性的后果。)
因此,术语“TCP 连接”指的是 TCP 协议的应用。该协议自然是有状态的,并且通常以 SYN-ACK-data-FIN 序列进行,或者在传输被拒绝的情况下以 SYN/RST 进行;两个对等方都维护连接的状态(握手、已建立、关闭、关闭)。TCP 还引入了术语“服务器”和“客户端”,服务器是
listen()
的对等方传入连接。Let's break this up into parts. First of, the network is based in IP, which is a protocol that assigns an address to each network node, and which allows you to send small amounts of data (usually up to 64kB, but typically only 1500B) from one node to another.
That by itself isn't worth much yet, because we can't make any checks that the data actually arrived, and that it arrived in the right order. If we want an abstract mechanism to transmit arbitrary amounts of data and ensure that they arrived, we need another protocol on top of the network that handles this "transmission". And that's the purpose of TCP.
However, in parallel to TCP, there's another "transmission" protocol that doesn't do any checking at all and has no reliability, UDP. UDP is just a thin wrapper around raw IP packets, which adds a little bit of meta data (like a port number).
UDP is still useful, though, since there are many situations in which the data integrity is already handed off to an even higher protocol, so there's no need for a complex transmission protocol. This is for example used in virtual networking services, where another instance of TCP/IP is typically run over a UDP channel. (Making the channel use a reliable protocol like TCP can actually have disastrous consequences in that case due to resend cascades.)
So the term "TCP connection" refers to the application of the TCProtocol. The protocol is stateful, naturally, and typically proceeds in a SYN-ACK-data-FIN sequence, or SYN/RST in case of a rejected transmission; both peers maintain a status of the connection (handshake, established, closing, closed.) TCP also introduces the terms "server" and "client", the server being the peer that
listen()
s for an incoming connection.TCP 和 UDP 套接字之间的主要区别在于 UDP 是无连接的,并且不使用任何另一端收到数据的确认。
The main difference between TCP and UDP sockets is that UDP is conectionless and doesn't use any confirmation that the other end received the data.