Upraviť

Zdieľať cez


TcpListener.ExclusiveAddressUse Property

Definition

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

public:
 property bool ExclusiveAddressUse { bool get(); void set(bool value); };
public bool ExclusiveAddressUse { get; set; }
member this.ExclusiveAddressUse : bool with get, set
Public Property ExclusiveAddressUse As Boolean

Property Value

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.

Exceptions

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

An error occurred when attempting to access the underlying socket.

The underlying Socket has been closed.

Examples

The following code example gets and sets the ExclusiveAddressUse property.

public:
    static void GetSetExclusiveAddressUse(TcpListener^ listener)
    {
        // Set Exclusive Address Use for the underlying socket.
        listener->ExclusiveAddressUse = true;
        Console::WriteLine("ExclusiveAddressUse value is {0}",
            listener->ExclusiveAddressUse);
    }
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);
}
Public Shared Sub GetSetExclusiveAddressUse(t As TcpListener)
   ' Set Exclusive Address Use for the underlying socket.
   t.ExclusiveAddressUse = True
   Console.WriteLine("ExclusiveAddressUse value is {0}", t.ExclusiveAddressUse)
End Sub

Remarks

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.

Applies to