Why can't different servers bind to the same port?

I am confused in the ports.

It seems strange to me that we need to connect different servers with different ports.

Example: Apache bound to 8080, Express.js cannot communicate on 8080

How is server port binding different from listening to an application port?

Example: Various browsers, i.e. Chrome, firefox, can listen and chat on port 80?

This problem occurred while trying to run the "grunt: unit test". There was a tomcat server that was already connected to the 8080, but server grunt is starting, middleware that I believe can run, but it cannot capture the browser. Stopping the tomcat server made everything work.

+1
source share
2 answers

Actually Firefox, Chrome, etc. use different source ports. They do not listen to ports; they connect to remote servers. Servers listen on one port (80). The source port from which the browser connects is randomly selected and is a large number. You can verify this using netstat. Their destination port is the same (80).

The reason you cannot connect multiple servers to the same port * is because the operating system does not know which application will send the incoming connection.

* Actually, you can, but it's difficult. SO_REUSEPORT

+4
source

, / : , , 80, , , ?

, -, , - ( , - 62332 - ), , , 80.

, .

+1

All Articles