TCP standard has \"simultaneous open\" feature.
The implication of the feature, client trying to connect to local port, when the port is from ephemeral range, can o
Bind the client socket to port 0 (system assigns), check the system assigned port, if it matches the local server port you already know the server is down and and can skip connect().