给定的目标端口可以与多个TCP连接关联吗?

发布于 2025-01-29 06:24:22 字数 233 浏览 2 评论 0原文

在进行了一些搜索之后,我了解了几点,

  1. 我们无法为TCP复用一个端口。
  2. 如果两个连接使用相同的协议并具有相同的目标端口,则它们必须具有相同的连接。
  3. 我对某些网站的说法如何在同一端口上只能在同一端口上听一个应用程序,而其他人则说多个侦听TCP插座都可以共存,我很困惑不同的本地IP地址。

阅读上述内容使我比以往任何时候都更加困惑。目标端口可以与多个TCP连接关联吗?

After doing some search for this, I got to know a few points

  1. We cannot multiplex a port for TCP.
  2. If two connections use the same protocol and have the same destination ports, they must have the same connection.
  3. I am quite confused about how some sites say that TCP can only have one application listening on the same port at one time while others say multiple listening TCP sockets, all bound to the same port, can co-exist, provided they are all bound to different local IP addresses.

Reading the above stuff has left me more confused than ever. Can a destination port be associated with more than one TCP connection?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

软甜啾 2025-02-05 06:24:22

我们无法将TCP的端口复用。

这是错误的。您 can 只要它们是唯一的连接,在同一端口上运行多个TCP连接。并且在同一过程中编写在多个TCP插座上多倍I/O的代码并不难。

如果两个连接使用相同的协议并且具有相同的目标端口,则必须具有相同的连接。

这是错误的。 TCP连接是通过协议 +本地IP/port +和远程IP/端口的组合唯一标识的。

如果使用不同的源IP/端口来连接,则使用相同协议和相同目标IP/端口的两个连接仍然是唯一的。例如,如果在同一台计算机上运行的多个客户端使用其他本地端口要连接,则可以连接到同一服务器。通常情况下,由于大多数客户使用由OS选择的随机可用本地端口进行出站连接。

同样,如果连接到其他目标IP/端口,使用相同协议和相同源IP/端口的两个连接仍然是唯一的。例如,在同一台计算机上运行的多个客户端可以使用相同的本地IP/端口连接到不同的服务器。

有些网站说TCP一次只能在同一端口上听一个应用程序

这是正确的,但是只有所有听众都试图同时使用相同的本地IP/端口。上面只允许1个听众。

其他人说,只要它们都绑定到其他本地IP地址。

这是正确的。

目标端口可以与多个TCP连接关联吗?

是的。即使该端口上只有1个侦听器,它接受的每个连接都将在服务器端使用相同的本地端口,但是与客户端端不同的源IP/端口。这允许来自不同远程计算机的多个客户端同时连接到同一服务器。

We cannot multiplex a port for TCP.

This is wrong. You can run multiple TCP connections on the same port, as long as they are unique connections. And it is not very difficult to write code that multiplexes I/O on multiple TCP sockets within the same process.

If two connections use the same protocol and have the same destination ports, they must have the same connection.

This is wrong. A TCP connection is uniquely identified by a combination of protocol + local IP/port + and remote IP/port.

Two connections that use the same protocol and same destination IP/port are still unique if they use different source IP/port to connect from. For instance, multiple clients running on the same machine can connect to the same server if they use a different local port to connect from. Which is typically the case, as most clients use a random available local port, selected by the OS, for the outbound connection.

Likewise, two connections that use the same protocol and the same source IP/port are still unique if they connect to different destination IP/port. For instance, multiple clients running on the same machine can use the same local IP/port to connect from if they connect to different servers.

some sites say that TCP can only have one application listening on the same port at one time

This is correct, but only if all of the listeners are trying to use the same local IP/port at the same time. Only 1 listener is allowed on it.

others say multiple listening TCP sockets, all bound to the same port, can co-exist, provided they are all bound to different local IP addresses.

This is correct.

Can a destination port be associated with more than one TCP connection?

Yes. Even if there is only 1 listener on that port, every connection it accepts will be using that same local port on the server side, but a different source IP/port from the client side. This allows multiple clients from different remote machines to connect to the same server at the same time.

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