在协议设计中,为什么要使用 2 个端口? [英] In protocol design, why would you ever use 2 ports?

查看:19
本文介绍了在协议设计中,为什么要使用 2 个端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当 TCP 服务器在端口上接受套接字时,它会获得一个新的套接字来与该客户端一起工作.
接受套接字对该端口仍然有效,并且可以接受该端口上的更多客户端.

When a TCP Server does a socket accept on a port, it gets a new socket to work with that Client.
The accepting socket remains valid for that port and can accept further clients on that port.

为什么最初的 FTP 规范 RFC 959 决定同时创建控制端口和数据端口?

Why did the original FTP specification RFC 959 decide to create both a control port and a data port?

是否有任何理由在类似的自定义协议中这样做?

在我看来,这可以很容易地在单个端口上指定.

It seems to me that this could have been easily specified on a single port.

考虑到防火墙和 NATS 与 FTP 的所有问题,似乎单个端口会好得多.

Given all the problems with firewalls and NATS with FTP, it seems that a single port would have been much better.

对于一般协议实现,我认为您想要这样做的唯一原因是您可以从不同于命令的主机提供文件.

For a general protocol implementation, the only reason I could think that you would want to do this is so that you can serve the files from a different host than the commands are going to.

推荐答案

这背后的最初理由是,你可以:

The initial rationale behind this was so that you could:

  • 在传输数据时继续在控制连接上发送和接收控制指令.
  • 同时有多个数据连接处于活动状态.
  • 服务器决定何时准备好向您发送数据.

的确,他们可以通过指定一个集成到 FTP 协议中的复杂多路复用协议来获得相同的结果,但由于当时 NAT 不是问题,他们选择使用已经存在的 TCP 端口.

True, they could have achieved the same result by specifying a complicated multiplexing protocol integrated to the FTP protocol, but since at that time NAT was a non issue, they chose to use what already existed, TCP ports.

这是一个例子:

Alice 想要 Bob 的两个文件.Alice 连接到 Bob 端口 21 并请求文件.Bob 准备好后打开与 Alice 端口 20 的连接并将文件发送到那里.同时,Charles 需要 Alice 服务器上的文件.Charles 连接到 Alice 上的 21 并请求文件.Alice 准备好后连接到 Charles 的 20 端口,并发送文件.

Alice wants two files from Bob. Alice connects to Bob port 21 and asks for the files. Bob open connections to Alice port 20 when it's ready and send the files there. Meanwhile, Charles needs a file on Alice's server. Charles connects to 21 on Alice and asks for the file. Alice connects to port 20 on Charles when ready, and sends the files.

如您所见,端口 21 用于客户端连接到服务器,端口 20 用于服务器连接到客户端,但这些客户端仍然可以在 21 上提供文件.

As you can see, port 21 is for client connecting to servers and port 20 is for servers connecting to clients, but those clients could still serve files on 21.

两个端口的用途完全不同,为了简单起见,他们选择使用两个不同的端口,而不是实现协商协议.

Both ports serve a totally different purpose, and again for sake of simplicity, they chose to use two different ports instead of implementing a negotiation protocol.

这篇关于在协议设计中,为什么要使用 2 个端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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