这是我所在组织的一位软件工程师提出的问题。我感兴趣的是最广义的定义。
当前回答
港口定义
文顿·g·瑟夫和罗伯特·e·卡恩(1974年5月)。分组网络互通协议。IEEE通讯汇刊,第22卷,第5号。IEEE。
端口是“一对(实体)在一段时间内交换一条或多条消息”的单元。
“……我们可以看到一个端口产生的消息序列,就好像它嵌入在一个无限长的字节流中……我们强调,与给定数据包相关联的序列号仅对通信的端口对是唯一的…对到达的数据包进行检查,以确定它们要发送到哪个端口。目标进程应该指定它愿意侦听特定端口或‘任何’端口。”
一个“端口只是一个的指示器……双工…消息流……[在一个或多个]信息流中…与流程相关联。”
信息科学研究所:南加州大学(1981年9月)。RFC 793:传输控制协议:DARPA互联网程序协议规范。
端口是一个或多个实体的一个实体,进程通过一个或多个通信流与一个或多个其他进程通信。
由于一个进程可能需要区分它自己和另一个进程(或多个进程)之间的几个通信流,我们设想每个进程都可能有若干端口,通过这些端口与其他进程通信。
“这样做的目的是,只允许在具有完全相同的安全性和隔间值的端口之间进行连接,并且在两个端口要求的优先级中具有更高的优先级。” 注意,此检查放在顺序检查之后,以防止来自这些具有不同安全性或优先级的端口之间的旧连接的段导致当前连接中断。
端口是一个地址,它指定进程的哪个逻辑输入或输出通道与[数据流]相关联。 为了允许单个主机内的多个进程同时使用TCP通信设施,TCP在每台主机内提供了一组地址或端口。
套接字中指定进程的哪个逻辑输入或输出通道与数据相关联的部分。
Socket的定义
甲骨文(2020)。类套接字。Java平台,标准版7 API规范。
套接字是两台机器之间通信的端点。
信息科学研究所:南加州大学(1981年9月)。RFC 793:传输控制协议:DARPA互联网程序协议规范。
A socket is a string consisting of an Internet address [i.e., the first eight-bit number (e.g., 123) of a network address (e.g., 123.45.78.0), a period, the second eight-bit number (e.g., 45) of the network address, a period, the third eight-bit number (e.g., 78) of the network address, a period, and a host address (e.g., 90)], a colon, and a TCP port (e.g., 1234). A socket is a unit of “A pair of [entities that] uniquely identify [a] connection[, and that] may be simultaneously used in multiple connections.”
"To allow for many processes within a single Host to use TCP communication facilities simultaneously, the TCP provides a set of addresses or ports within each host. Concatenated with the network and host addresses from the internet communication layer, this forms a socket. A pair of sockets uniquely identifies each connection. That is, a socket may be simultaneously used in multiple connections." “To provide for unique addresses within each TCP, we concatenate an internet address identifying the TCP with a port identifier to create a socket which will be unique throughout all networks connected together.”
上面描述的可靠性和流量控制机制要求tcp初始化和维护每个数据流的特定状态信息。这些信息(包括套接字、序列号和窗口大小)的组合称为连接。每个连接都由一对识别其两端的套接字唯一指定。”
其他回答
相对的TCP/IP术语,我认为这是隐含的问题。通俗地说:
PORT类似于特定邮政编码中特定房屋的电话号码。城镇的邮政编码可以被认为是城镇和城镇中所有房屋的IP地址。
另一方面,SOCKET更像是一对房屋之间的电话之间的通话。这些呼叫可以在同一城镇的房屋之间建立,也可以在不同城镇的两所房屋之间建立。这对手机之间建立的临时通道就是SOCKET。
简短的回答。
端口可以被描述为主机中的内部地址,用于标识程序或进程。
套接字可以被描述为一个编程接口,允许一个程序在internet上或本地与其他程序或进程通信。
港口定义
文顿·g·瑟夫和罗伯特·e·卡恩(1974年5月)。分组网络互通协议。IEEE通讯汇刊,第22卷,第5号。IEEE。
端口是“一对(实体)在一段时间内交换一条或多条消息”的单元。
“……我们可以看到一个端口产生的消息序列,就好像它嵌入在一个无限长的字节流中……我们强调,与给定数据包相关联的序列号仅对通信的端口对是唯一的…对到达的数据包进行检查,以确定它们要发送到哪个端口。目标进程应该指定它愿意侦听特定端口或‘任何’端口。”
一个“端口只是一个的指示器……双工…消息流……[在一个或多个]信息流中…与流程相关联。”
信息科学研究所:南加州大学(1981年9月)。RFC 793:传输控制协议:DARPA互联网程序协议规范。
端口是一个或多个实体的一个实体,进程通过一个或多个通信流与一个或多个其他进程通信。
由于一个进程可能需要区分它自己和另一个进程(或多个进程)之间的几个通信流,我们设想每个进程都可能有若干端口,通过这些端口与其他进程通信。
“这样做的目的是,只允许在具有完全相同的安全性和隔间值的端口之间进行连接,并且在两个端口要求的优先级中具有更高的优先级。” 注意,此检查放在顺序检查之后,以防止来自这些具有不同安全性或优先级的端口之间的旧连接的段导致当前连接中断。
端口是一个地址,它指定进程的哪个逻辑输入或输出通道与[数据流]相关联。 为了允许单个主机内的多个进程同时使用TCP通信设施,TCP在每台主机内提供了一组地址或端口。
套接字中指定进程的哪个逻辑输入或输出通道与数据相关联的部分。
Socket的定义
甲骨文(2020)。类套接字。Java平台,标准版7 API规范。
套接字是两台机器之间通信的端点。
信息科学研究所:南加州大学(1981年9月)。RFC 793:传输控制协议:DARPA互联网程序协议规范。
A socket is a string consisting of an Internet address [i.e., the first eight-bit number (e.g., 123) of a network address (e.g., 123.45.78.0), a period, the second eight-bit number (e.g., 45) of the network address, a period, the third eight-bit number (e.g., 78) of the network address, a period, and a host address (e.g., 90)], a colon, and a TCP port (e.g., 1234). A socket is a unit of “A pair of [entities that] uniquely identify [a] connection[, and that] may be simultaneously used in multiple connections.”
"To allow for many processes within a single Host to use TCP communication facilities simultaneously, the TCP provides a set of addresses or ports within each host. Concatenated with the network and host addresses from the internet communication layer, this forms a socket. A pair of sockets uniquely identifies each connection. That is, a socket may be simultaneously used in multiple connections." “To provide for unique addresses within each TCP, we concatenate an internet address identifying the TCP with a port identifier to create a socket which will be unique throughout all networks connected together.”
上面描述的可靠性和流量控制机制要求tcp初始化和维护每个数据流的特定状态信息。这些信息(包括套接字、序列号和窗口大小)的组合称为连接。每个连接都由一对识别其两端的套接字唯一指定。”
这个问题已经有了理论上的答案。我想举一个实际的例子来解释这个问题,让大家对Socket和Port有一个更清晰的理解。
我在这里找到的
This example will walk you thru the process of connecting to a website, such as Wiley. You would open your web browser (like Mozilla Firefox) and type www.wiley.com into the address bar. Your web browser uses a Domain Name System (DNS) server to look up the name www.wiley.com to identify its IP address is. For this example, the address is 192.0.2.100. Firefox makes a connection to the 192.0.2.100 address and to the port where the application layer web server is operating. Firefox knows what port to expect because it is a well-known port . The well-known port for a web server is TCP port 80. The destination socket that Firefox attempts to connect is written as socket:port, or in this example, 192.0.2.100:80. This is the server side of the connect, but the server needs to know where to send the web page you want to view in Mozilla Firefox, so you have a socket for the client side of the connection also. The client side connection is made up of your IP address, such as 192.168.1.25, and a randomly chosen dynamic port number. The socket associated with Firefox looks like 192.168.1.25:49175. Because web servers operate on TCP port 80, both of these sockets are TCP sockets, whereas if you were connecting to a server operating on a UDP port, both the server and client sockets would be UDP sockets.
套接字地址是一个IP地址和端口号
123.132.213.231 # IP address
:1234 # port number
123.132.213.231:1234 # socket address
当两个套接字绑定在一起时,就发生了连接。
推荐文章
- 我可以在/etc/hosts中映射主机名*和端口*吗?
- 如何修改Play执行run命令时使用的默认端口(9000)?
- 连接网络共享时,如何提供用户名和密码
- 如何找到可用的端口?
- 如何通过windows命令行关闭TCP和UDP端口
- UDP和TCP比起来快多少?
- ssh -L转发多个端口
- 一个干净、轻量级的Python扭曲的替代品?
- 套接字的连接超时和读超时之间的区别是什么?
- 将主机端口转发到docker容器
- 远程主机强制关闭现有连接
- TCP连接的最大数据包大小
- connectexception:拒绝连接
- Docker -绑定0.0.0.0:4000失败:端口已经分配
- Node.js中的process.env.PORT是什么?