I know that a web server running a website on TCP port 80 can receive TCP connections from many different IP addresses sourced from many different ephemeral ports.

Can a client initiate multiple connections (complete the TCP 3-way handshake) to different web servers on TCP port 80 using the same ephemeral port?

For example:

Source Port: 55555, Destination Port: 80, Destination IP:
Source Port: 55555, Destination Port: 80, Destination IP:
Source Port: 55555, Destination Port: 80, Destination IP:

If the first connection using port 55555 has been closed, it may be reused by any application. If an application tries to open the same port which is used by another application, the OS will respond that the port is already in use.

One caveat is that the application which has opened the port with TCP can use it as it see fit, including using it for multiple servers, but all the multiplexing work is on the application, not TCP.

  • If that's the case, how do web servers re-use the same TCP source port (80) and have different IP addresses (the client IPs) for the other side of the connection? They are all open at the same time. – slantalpha Mar 9 '16 at 4:56
  • 1
    The web servers handle it because the sockets are based on four things, the source and destination IP addresses, and the source and destination ports. In effect, the application (web server) handles the multiplexing. You can do the same thing with a web browser, or any other application. Whether or not an application does this is up to the application designers and coders. – Ron Maupin Mar 9 '16 at 4:58
  • So getting back to my original question, it's possible for the client to build multiple TCP connections using the same ephemeral port to different IP addresses and port combinations, but the application using the ephemeral port would need to support multiplexing? And the TCP connections wouldn't be kept separate by the TCP/IP stack? – slantalpha Mar 9 '16 at 15:50
  • 1
    That would be correct. As far as layer-4 (TCP) is concerned, a port is an application address, and anything coming into the port which an application has reserved gets sent to the application. Whatever the application sends to another application on a different host gets the local port number as the return address, layer-3 (IP) will get the TCP segment, encapsulate it in a packet, address it for network delivery, layer-2 encapsulates it in a frame for LAN delivery, and layer-1 puts it on the wire. It's all reversed at the other end. – Ron Maupin Mar 9 '16 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.