In the description of TCP in the Wikipedia, it is stated that
The number of sessions in the server side is limited only by memory and can grow as new connections arrive, but the client must allocate a random port before sending the first SYN to the server.
The first part seems logical: The server simply uses the port that the clients have connected to as the source port, and is thereby only limited by (number of client IPs) * (number of ephemeral client ports) - a big number.
But why can't the clients do basically the same thing? If socket A connects to server1 using ephemeral port 12345 (e.g. client:12345 -> server1:80), why can't socket B connect to server 2 by reusing the same source port (client:12345 -> server2:80)? That would allow more than (number of ports) outgoing TCP connections from a single host.
Is there something in the TCP specification that prohibits that kind of port reuse, or is the limitation only a practical result of common TCP implementations? If so, is the first case really handled in a different way than the second one, or is the number of incoming TCP connections on a single server port practically also limited to 65535?
To clarify, I'm looking for the theoretical (according to the specs) and practical (implementations; especially Linux) limits for:
- Outgoing connections from a single client to ANY server/port.
(client:* -> *:*)
- Connections from a single client to the SAME server and port
(client:* -> server:port)- this can obviously not be greater than 65535.
- Incoming connections to a single server port from ANY client
(*:* -> server:port)- I suspect this is greater than 65535 according to the quoted paragraph and the reasons stated above.