Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TcpListener.ExclusiveAddressUse Property

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.
ExceptionCondition
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.

Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 Platform Note: The default value for this property is true for Service Pack 2 and later.

Windows Server 2003 Platform Note: The default value for this property is true.

Windows 2000 Platform Note: The application must run as Administrator to use this property.

Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 Platform Note: 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

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft. All rights reserved.