开发者

What is SocketOptionName.ReuseAddress used for?

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.

I开发者_开发问答f 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜