We all know that a socket is a two-way communication link between two processes on a network,
Socket = IP address of a process: port number, IP address of process B: Port number
Then there is a problem is interesting, different processes can listen to the same IP address: port number?
According to the Knowledge of UNIX network programming, the service side listens to a port to experience:
1. Create socket sockets based on socket type (IPV4,IPV6, etc.)
2. Bind socket bind to specific network address and port number
3. Call listen to start listening on this socket.
UNIX provides an interface that setsockopt () can set socket options before bind, including the reuseaddr option, which indicates that multiple processes can reuse the address and port number specified in the BIND function.
It can be concluded that multiple applications (processes), including the same application multiple times, are bound to the same port for listening. Corresponding interfaces are also available in high-level languages such as C + + and net.
As you can see from some examples, sometimes when you perform Netstat-ano on a server, you may find that the same application has multiple listeners on the same port because some service-side applications may exit abnormally or not completely release the socket. However, this is also the case when you need to be able to listen to the same port again at reboot, so you need the ability to listen to the same ports repeatedly.
Network: Can multiple processes listen to the same port number?