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


当前回答

套接字由三部分组成:

IP地址 传输协议 端口号

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

例如:

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

其他回答

套接字基本上是网络通信的端点,至少由一个ip地址和一个端口组成。在Java/ c#中,套接字是双向连接一侧的高级实现。

还有Java教程中的一个(非规范的)定义。

从Oracle Java教程:

套接字是网络上运行的两个程序之间双向通信链路的一个端点。套接字与端口号绑定,以便TCP层可以识别数据要发送到的应用程序。

它们是来自两个不同领域的术语:“端口”是TCP/IP网络的概念,“套接字”是API(编程)的东西。“套接字”是通过将端口和主机名或网络适配器组合成一个数据结构(可以用来发送或接收数据)而形成的(在代码中)。

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一起就像给套接字提供一个地址,虽然不是必需的,但它有助于网络通信。

简短的回答。

端口可以被描述为主机中的内部地址,用于标识程序或进程。

套接字可以被描述为一个编程接口,允许一个程序在internet上或本地与其他程序或进程通信。