Changes in Socket Bind
MSDN finally has the "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE" doc online. I previously posted it on this blog but the formatting came out a bit funky. Here's the link:
We've received some feedback on the article saying it doesn't explicitly spell out all the changes in socket bind behavior. The tables in the doc do describe all the various combinations and their results but here are a couple key differences:
- To bind two sockets to the same address and port, the first socket bound to the address and port *must* set SO_REUSEADDR to indicate it will allow others to hijack it -- this requirement is new. The second socket still needs to set SO_REUSEADDR which is the same behavior as before.
- Without setting any options it is possible for two sockets to be bound to the same address and port. If the first socket binds to the wildcard address and port X (e.g. 0.0.0.0:5150) another socket may come along and bind to an explicit address and port X (e.g. 127.0.0.1:5150). In this case, the first socket is now listening on port 5150 for every local interface except 127.0.0.1. Note: This is only true if both sockets are created under the same user context.
--Anthony Jones (ajones)