ExclusiveAddressUse Property

TcpClient.ExclusiveAddressUse Property

 

Gets or sets a Boolean value that specifies whether the TcpClient allows only one client to use a port.

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

public bool ExclusiveAddressUse { get; set; }

Property Value

Type: System.Boolean

true if the TcpClient allows only one client to use 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
SocketException

An error occurred when attempting to access the underlying socket.

ObjectDisposedException

The underlying Socket has been closed.

By default, multiple clients can use a specific port; however, only one of the clients can perform operations on the network traffic sent to the port. You can use the ExclusiveAddressUse property to prevent multiple clients from using a specific port.

This property must be set before the underlying socket is bound to a client port. If you call Connect, BeginConnect, TcpClient(IPEndPoint), or TcpClient(String, Int32), the client port is bound as a side effect of the method, and you cannot subsequently set the ExclusiveAddressUse property

WinXpFamily

The default value for this property is true for Service Pack 2 and later. For Service Pack 1, the application must run as Administrator to use this property.

Win2003Server

The default value for this property is true.

Win2kFamily

The application must run as Administrator to use this property.

The following code example creates a TcpClient and gets and sets the value of the ExclusiveAddressUse property.

static void GetSetExclusiveAddressUse()
{
    // Don't allow another process to bind to this port.
    t.ExclusiveAddressUse = true;
    Console.WriteLine("ExclusiveAddressUse value is {0}",
        t.ExclusiveAddressUse);
}

Universal Windows Platform
Available since 10
.NET Framework
Available since 2.0
Return to top
Show:
© 2016 Microsoft