这是我所在组织的一位软件工程师提出的问题。我感兴趣的是最广义的定义。


当前回答

单个端口可以有一个或多个连接不同外部IP的插座,如多个电源插座。

  TCP    192.168.100.2:9001     155.94.246.179:39255   ESTABLISHED     1312
  TCP    192.168.100.2:9001     171.25.193.9:61832     ESTABLISHED     1312
  TCP    192.168.100.2:9001     178.62.199.226:37912   ESTABLISHED     1312
  TCP    192.168.100.2:9001     188.193.64.150:40900   ESTABLISHED     1312
  TCP    192.168.100.2:9001     198.23.194.149:43970   ESTABLISHED     1312
  TCP    192.168.100.2:9001     198.49.73.11:38842     ESTABLISHED     1312

其他回答

套接字是一种数据I/O机制。端口是通信协议的契约概念。套接字可以没有端口而存在。一个端口可以没有特定的套接字而存在(例如,如果同一个端口上有几个活动的套接字,这可能是某些协议允许的)。

端口用于确定接收端应该将数据包路由到哪个套接字,在许多协议中,但它并不总是必需的,接收套接字的选择可以通过其他方式完成——端口完全是网络子系统中协议处理程序使用的工具。例如,如果协议不使用端口,数据包可以到所有侦听套接字或任何套接字。

套接字由三部分组成:

IP地址 传输协议 端口号

端口是1到65535之间的数字,表示设备中的逻辑门。 客户端和服务器之间的每个连接都需要一个惟一的套接字。

例如:

1030为端口。 (10.1.1.2, TCP,端口1030)是一个套接字。

Socket is an abstraction provided by kernel to user applications for data I/O. A socket type is defined by the protocol it's handling, an IPC communication etc. So if somebody creates a TCP socket he can do manipulations like reading data to socket and writing data to it by simple methods and the lower level protocol handling like TCP conversions and forwarding packets to lower level network protocols is done by the particular socket implementation in the kernel. The advantage is that user need not worry about handling protocol specific nitigrities and should just read and write data to socket like a normal buffer. Same is true in case of IPC, user just reads and writes data to socket and kernel handles all lower level details based on the type of socket created.

端口和IP一起就像给套接字提供一个地址,虽然不是必需的,但它有助于网络通信。

端口:

端口可以指物理连接点 用于外部设备,如串行、并行和USB端口。 术语端口也指某些以太网连接点 如集线器、交换机或路由器上的那些。

套接字:

套接字表示两个网络应用程序之间的单个连接。 这两个应用程序名义上运行在不同的计算机上, 但是套接字也可以用于单台计算机上的进程间通信。 应用程序可以创建多个套接字用于相互通信。 套接字是双向的,这意味着连接的任何一方都能够发送和接收数据。

港口定义

文顿·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初始化和维护每个数据流的特定状态信息。这些信息(包括套接字、序列号和窗口大小)的组合称为连接。每个连接都由一对识别其两端的套接字唯一指定。”