Uredi

Deli z drugimi prek


UdpClient.ExclusiveAddressUse Property

Definition

Gets or sets a Boolean value that specifies whether the UdpClient allows only one client to use a 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 UdpClient 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.

Exceptions

An error occurred when attempting to access the underlying socket.

The underlying Socket has been closed.

Examples

The following code example creates a UdpClient, and gets and sets the ExclusiveAddressUse property.

static void GetSetExclusiveAddressUse( UdpClient^ u )
{
   // Don't allow another client to bind to this port.
   u->ExclusiveAddressUse = true;
   Console::WriteLine(  "ExclusiveAddressUse value is {0}", u->ExclusiveAddressUse );
}
public static void GetSetExclusiveAddressUse(UdpClient u)
{
    // Don't allow another client to bind to this port.
    u.ExclusiveAddressUse = true;
    Console.WriteLine("ExclusiveAddressUse value is {0}",
        u.ExclusiveAddressUse);
}

Remarks

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 UdpClient.UdpClient(Int32), UdpClient.UdpClient(Int32, AddressFamily), UdpClient.UdpClient(IPEndPoint), or UdpClient.UdpClient(String, Int32), the client port is bound as a side effect of the constructor, and you cannot subsequently set the ExclusiveAddressUse property

Applies to