Socket.ExclusiveAddressUse Eigenschap

Definitie

Hiermee wordt een waarde opgehaald of ingesteld waarmee wordt aangegeven of slechts Socket één proces verbinding kan maken met een poort.

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

Waarde van eigenschap

trueals het Socket slechts één socket toestaat om te binden aan een specifieke poort; anders. false De standaardwaarde is true voor Windows Server 2003 en Windows XP en nieuwere versies.

Uitzonderingen

Er is een fout opgetreden bij het openen van de socket.

Voorbeelden

In het volgende codevoorbeeld ziet u hoe de ExclusiveAddressUse eigenschap wordt gebruikt.

static void ConfigureTcpSocket(Socket tcpSocket)
{
    // Don't allow another socket to bind to this port.
    tcpSocket.ExclusiveAddressUse = true;

    // The socket will linger for 10 seconds after
    // Socket.Close is called.
    tcpSocket.LingerState = new LingerOption (true, 10);

    // Disable the Nagle Algorithm for this tcp socket.
    tcpSocket.NoDelay = true;

    // Set the receive buffer size to 8k
    tcpSocket.ReceiveBufferSize = 8192;

    // Set the timeout for synchronous receive methods to
    // 1 second (1000 milliseconds.)
    tcpSocket.ReceiveTimeout = 1000;

    // Set the send buffer size to 8k.
    tcpSocket.SendBufferSize = 8192;

    // Set the timeout for synchronous send methods
    // to 1 second (1000 milliseconds.)
    tcpSocket.SendTimeout = 1000;

    // Set the Time To Live (TTL) to 42 router hops.
    tcpSocket.Ttl = 42;

    Console.WriteLine("Tcp Socket configured:");

    Console.WriteLine($"  ExclusiveAddressUse {tcpSocket.ExclusiveAddressUse}");

    Console.WriteLine($"  LingerState {tcpSocket.LingerState.Enabled}, {tcpSocket.LingerState.LingerTime}");

    Console.WriteLine($"  NoDelay {tcpSocket.NoDelay}");

    Console.WriteLine($"  ReceiveBufferSize {tcpSocket.ReceiveBufferSize}");

    Console.WriteLine($"  ReceiveTimeout {tcpSocket.ReceiveTimeout}");

    Console.WriteLine($"  SendBufferSize {tcpSocket.SendBufferSize}");

    Console.WriteLine($"  SendTimeout {tcpSocket.SendTimeout}");

    Console.WriteLine($"  Ttl {tcpSocket.Ttl}");

    Console.WriteLine($"  IsBound {tcpSocket.IsBound}");

    Console.WriteLine("");
}

Opmerkingen

Als ExclusiveAddressUse dat het zo is false, kunnen meerdere sockets de Bind methode gebruiken om verbinding te maken met een specifieke poort, maar slechts één van de sockets kan bewerkingen uitvoeren op het netwerkverkeer dat naar de poort wordt verzonden. Als meer dan één socket de Bind(EndPoint) methode probeert te gebruiken om verbinding te maken met een bepaalde poort, wordt het netwerkverkeer dat naar die poort wordt verzonden, verwerkt het ip-adres met het specifiekere IP-adres.

Als ExclusiveAddressUse dit het geval is true, slaagt het eerste gebruik van de Bind methode om verbinding te maken met een bepaalde poort, ongeacht het IP-adres (Internet Protocol). Alle volgende toepassingen van de Bind methode om verbinding te maken met die poort mislukken totdat de oorspronkelijke gebonden socket wordt vernietigd.

Deze eigenschap moet worden ingesteld voordat Bind wordt aangeroepen. Anders wordt er een InvalidOperationException gegenereerd.

Van toepassing op