On the same machine, if a tcp client has occupied port 12345, for example, the client has connected to google.com, and then a tcp server tries to bind its listening port on 12345, is this allowed?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The answer is “it depends” (on OS and socket options).
On Linux with
SO_REUSEADDRon both sockets, the exact situation described is possible:…but only when the client gets there first. When the server is already listening, the same port can’t be bound by client (and won’t ever be automatically assigned to client, IIRC).
On Windows, with or without
SO_REUSEADDR, port is port andbindfails (be it the server or the client who did it first).