What is the practical use of Socket.ExclusiveAddressUse?

Recently, I have been working a bit with sockets in .NET, and I'm wondering what the practical use of Socket.ExclusiveAddressUse . I read the MSDN documentation , so I know the basic idea (forcing a specific combination of IP addresses / ports to allow only one socket to bind to it), but I'm a bit confused about the fact that the property is actually used.

The documentation states that ExclusiveAddressUse is false:

If several sockets try to use the Bind(EndPoint) method to bind to a specific port, then the one with a more specific IP address will handle network traffic sent to that port.

How exactly is one IPEndPoint (the only specific EndPoint subclass I can find) more specific than the other? How and why do you use this behavior in an application? Why will this behavior be by default in versions of Windows later than XP, but not earlier?

+4
source share
1 answer

For example, if you have:

 var endPoint = new IPEndPoint(IPAddress.IPv6Any, 800); using (var socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) { socket.Bind(endPoint); socket.Listen(int.MaxValue); socket.AcceptAsync(new SocketAsyncEventArgs().Completed += ...); } 

you will start listening for all incoming connections from all IPv6 addresses on port 800. Now, if you create another socket with the exact IP address on the same port, the new socket will take priority and will start listening on this exact IP address on port 800. This is useful for a smaller set of scenarios (i.e., for a transient connection where you read / write to the exact IP address using a secure channel).

+3
source

All Articles