TCP 与 UDP - 什么是 TCP 连接?

发布于 2024-12-16 11:51:49 字数 248 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月亮邮递员 2024-12-23 11:51:49

让我们把它分成几部分。首先,网络基于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.

故事与诗 2024-12-23 11:51:49

TCP 和 UDP 套接字之间的主要区别在于 UDP 是无连接的,并且不使用任何另一端收到数据的确认。

传输控制协议(TCP)是互联网协议族的核心协议之一。 TCP 是该套件的两个原始组件之一,是对 Internet 协议 (IP) 的补充,因此整个套件通常称为 TCP/IP。 TCP 提供从一台计算机上的程序到另一台计算机上的另一个程序的可靠、有序的字节流传送。 TCP 是万维网、电子邮件、远程管理和文件传输等主要互联网应用所依赖的协议。其他不需要可靠数据流服务的应用程序可以使用用户数据报协议 (UDP),该协议提供的数据报服务强调减少延迟而不是可靠性。1

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.

The Transmission Control Protocol (TCP) is one of the core protocols of the Internet Protocol Suite. TCP is one of the two original components of the suite, complementing the Internet Protocol (IP), and therefore the entire suite is commonly referred to as TCP/IP. TCP provides reliable, ordered delivery of a stream of bytes from a program on one computer to another program on another computer. TCP is the protocol that major Internet applications such as the World Wide Web, email, remote administration and file transfer rely on. Other applications, which do not require reliable data stream service, may use the User Datagram Protocol (UDP), which provides a datagram service that emphasizes reduced latency over reliability.1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文