非常经典的说明,可以经常看 socket与port
A TCP socket is an endpoint instance defined by an IP address and a port in the context of either a particular TCP connection or the listening state.
个人理解:
- 说套接字是需要上下文的。只有针对一个具体的tcp连接(不仅仅有自身的ip和端口,还有对方的ip和端口)或者监听状态(对于一个ip+port,只能由一个监听者。写程序时有时报错说端口已经被使用就是因为一个端口只能由一个监听者)时才有意义。套接字不是一个独立的概念,是必须在上述两种场景下才有意义的。
A port is a virtualisation identifier defining a service endpoint (as distinct from a service instance endpoint aka session identifier).
A TCP socket is not a connection, it is the endpoint of a specific connection.
There can be concurrent connections to a service endpoint, because a connection is identified by both its local and remote endpoints, allowing traffic to be routed to a specific service instance.
There can only be one listener socket for a given address/port combination.
网友评论