What is SocketOptionName.ReuseAddress used for?

I thought that using SocketOptionName.ReuseAddress , I can reuse a port that is in TIME_WAIT state. But I tried to experiment with him, and it seems that this has no effect.

If I check sockets using netstat and it shows that the socket is in TIME_WAIT state and I start the client again, I get an exception:

Only one use of each socket address is allowed (protocol / network address / port). 172.16.16.16:12345

I can do nothing of this. Please can you clarify what suits SocketOptionName.ReuseAddress?

+4
source share
1 answer

Why do you bind your client port in the first place? You probably do not need it, and if you do not, it is much better to let the OS select the ephemeral port for you, and then you will not have this problem in the first place.

Secondly, why do you think it is a good idea to reuse the socket, which is TIME_WAIT ; the state exists for a good reason ...

As to why it doesn’t work for you, take a look at the link I posted in response to this similar question: When binding a TCP client socket to a specific local port with Winsock, SO_REUSEADDR has no effect

0
source

Source: https://habr.com/ru/post/1308741/


All Articles