TcpClient.ExclusiveAddressUse Propriedade

Definição

Obtém ou define um valor Boolean que especifica se o TcpClient permite que um único cliente use uma porta.Gets or sets a Boolean value that specifies whether the TcpClient 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

Valor da propriedade

Boolean

true se o TcpClient permitir que apenas um cliente use uma porta específica; caso contrário, false.true if the TcpClient allows only one client to use a specific port; otherwise, false. O padrão é true para o Windows Server 2003 e Windows XP Service Pack 2 e posterior e false para todas as outras versões.The default is true for Windows Server 2003 and Windows XP Service Pack 2 and later, and false for all other versions.

Exceções

Erro ao tentar acessar o soquete subjacente.An error occurred when attempting to access the underlying socket.

O Socket subjacente foi fechado.The underlying Socket has been closed.

Exemplos

O exemplo de código a seguir cria um TcpClient e obtém e define o valor da ExclusiveAddressUse propriedade.The following code example creates a TcpClient and gets and sets the value of the ExclusiveAddressUse property.

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

Comentários

Por padrão, vários clientes podem usar uma porta específica; no entanto, somente um dos clientes pode executar operações no tráfego de rede enviado para a porta.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. Você pode usar a ExclusiveAddressUse propriedade para impedir que vários clientes usem uma porta específica.You can use the ExclusiveAddressUse property to prevent multiple clients from using a specific port.

Essa propriedade deve ser definida antes que o soquete subjacente esteja associado a uma porta do cliente.This property must be set before the underlying socket is bound to a client port. Se você chamar Connect , BeginConnect , TcpClient(IPEndPoint) ou TcpClient(String, Int32) , a porta do cliente será associada como um efeito colateral do método, e você não poderá definir a ExclusiveAddressUse Propriedade subsequentemente.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.

Aplica-se a