I used to think that using SocketOptionName.ReuseAddress
, I can reuse a port that is in TIME_WAIT
state. But I tried to experiment with it and it seems it has no effect.
If I check sockets using netstat
, and it shows the socket is in TIME_WAIT
state and I immediately run the client again, I get the exception:
Only one usage of each socket address (protocol/network address/port) is normally permitted 172.16.16.16:12345
I cannot make anything out of it. Please can you elaborate what SocketOptionName.ReuseAddress is good for?
Why are you binding your client port in the first place? You probably don't need to and if you don't then it's much better to allow the OS to select an ephemeral port for you and then you wouldn't have this problem in the first place.
Secondly, why do you think it's a good idea to reuse a socket that it's TIME_WAIT
; the state exists for a valid reason...
As for why it's not working for you, take a look at the link that I posted in answer to this similar question: When binding a client TCP socket to a specific local port with Winsock, SO_REUSEADDR does not have any effect
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With