TcpListener.ExclusiveAddressUse Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets a Boolean value that specifies whether the TcpListener allows only one underlying socket to listen to a specific port.

Namespace:   System.Net.Sockets
Assembly:  System (in System.dll)

public bool ExclusiveAddressUse { get; set; }

Property Value

Type: System.Boolean

true if the TcpListener allows only one TcpListener to listen to a specific port; otherwise, false. . The default is true for Windows Server 2003 and Windows XP Service Pack 2 and later, and false for all other versions.

Exception Condition
InvalidOperationException

The TcpListener has been started. Call the Stop() method and then set the ExclusiveAddressUse property.

SocketException

An error occurred when attempting to access the underlying socket.

ObjectDisposedException

The underlying Socket has been closed.

By default, multiple listeners can listen to a specific port. However, only one of the listeners can perform operations on the network traffic sent to the port. If more than one listener attempts to bind to a particular port, then the one with the more specific IP address handles the network traffic sent to that port. You can use the ExclusiveAddressUse property to prevent multiple listeners from listening to a specific port.

Set this property before calling Start, or call the Stop method and then set this property.

WinXpFamily

The default value for this property is true for Service Pack 2 and later.

Win2003Server

The default value for this property is true.

Win2kFamily

The application must run as Administrator to use this property.

WinXpFamily

For Service Pack 1, the application must run as Administrator to use this property.

The following code example gets and sets the ExclusiveAddressUse property.

public static void GetSetExclusiveAddressUse(TcpListener t)
{
    // Set Exclusive Address Use for the underlying socket.
    t.ExclusiveAddressUse = true;
    Console.WriteLine("ExclusiveAddressUse value is {0}",
        t.ExclusiveAddressUse);
}

.NET Framework
Available since 2.0
Return to top
Show: