这是我所在组织的一位软件工程师提出的问题。我感兴趣的是最广义的定义。
当前回答
套接字= IP地址+端口(数字地址) 它们一起标识机器上网络连接的端点。(我刚刚是不是网络基础课不及格?)
其他回答
An application consists of pair of processes which communicate over the network (client-server pair). These processes send and receive messages, into and from the network through a software interface called socket. Considering the analogy presented in the book "Computer Networking: Top Down Approach". There is a house that wants to communicate with other house. Here, house is analogous to a process, and door to a socket. Sending process assumes that there is a infrastructure on the other side of the door that will transport the data to the destination. Once the message is arrived on the other side, it passes through receiver's door (socket) into the house (process). This illustration from the same book can help you: Sockets are part of transport layer, which provides logical communication to applications. This means that from application's point of view both hosts are directly connected to each other, even though there are numerous routers and/or switches between them. Thus a socket is not a connection itself, it's the end point of the connection. Transport layer protocols are implemented only on hosts, and not on intermediate routers. Ports provide means of internal addressing to a machine. The primary purpose it to allow multiple processes to send and receive data over the network without interfering with other processes (their data). All sockets are provided with a port number. When a segment arrives to a host, the transport layer examines the destination port number of the segment. It then forwards the segment to the corresponding socket. This job of delivering the data in a transport layer segment to the correct socket is called de-multiplexing. The segment's data is then forwarded to the process attached to the socket.
套接字地址是一个IP地址和端口号
123.132.213.231 # IP address
:1234 # port number
123.132.213.231:1234 # socket address
当两个套接字绑定在一起时,就发生了连接。
套接字基本上是网络通信的端点,至少由一个ip地址和一个端口组成。在Java/ c#中,套接字是双向连接一侧的高级实现。
还有Java教程中的一个(非规范的)定义。
它们是来自两个不同领域的术语:“端口”是TCP/IP网络的概念,“套接字”是API(编程)的东西。“套接字”是通过将端口和主机名或网络适配器组合成一个数据结构(可以用来发送或接收数据)而形成的(在代码中)。
端口是网络协议用来访问连接的主机的实体。端口可以是特定于应用程序的,也可以是与特定通信媒介相关的。不同的协议使用不同的端口访问主机,如HTTP使用80端口或FTP使用23端口。您可以在应用程序中分配用户定义的端口号,但这些端口号应该大于1023。
端口打开到所需主机的连接,而套接字是网络间或进程间通信的端点。 套接字是由系统通过api(应用程序编程接口)分配的。
更微妙的区别是,当系统重新启动时,端口将出现,而套接字将被销毁。
推荐文章
- 在套接字编程中AF_INET和PF_INET的区别是什么?
- read()和recv(), send()和write()之间有什么区别?
- mysqld_safe UNIX套接字文件目录“/var/run/mysqld”不存在
- 如何解决“java.net.BindException: Address already in use: JVM_Bind”错误?
- 增加Linux中TCP/IP连接的最大数量
- 模拟慢速网络连接的网络工具
- 如何打开“谷歌计算引擎”中的特定端口(如9090)
- socket和websocket的区别?
- Android检查网络连接
- 465端口和587端口有什么区别?
- 什么是AF_INET,为什么我需要它?
- Kubernetes Service定义中targetPort和port的区别
- 停止node.js服务器的所有实例
- 现代Linux机顶盒理论上最大的TCP连接数是多少
- Linux上的网络使用top/htop