Socket.Ttl Eigenschap

Definitie

Hiermee wordt een waarde opgehaald of ingesteld waarmee de TTL-waarde (Time To Live) wordt opgegeven van IP-pakketten (Internet Protocol) die worden verzonden door de Socket.

public:
 property short Ttl { short get(); void set(short value); };
public short Ttl { get; set; }
member this.Ttl : int16 with get, set
Public Property Ttl As Short

Waarde van eigenschap

De TTL-waarde.

Uitzonderingen

De TTL-waarde is een negatief getal.

Het stopcontact bevindt zich niet in de InterNetwork of InterNetworkV6 families.

Er is een fout opgetreden bij het openen van de socket. Deze fout wordt ook geretourneerd wanneer er een poging is gedaan om TTL in te stellen op een waarde die hoger is dan 255.

Voorbeelden

In het volgende codevoorbeeld ziet u hoe de Ttl 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

De TTL-waarde geeft het maximum aantal routers aan dat het pakket kan passeren voordat de router het pakket negeert en een ICMP-foutbericht (Internet Control Message Protocol) "TTL overschreden" wordt geretourneerd aan de afzender.

De TTL-waarde kan worden ingesteld op een waarde van 0 tot 255. Als deze eigenschap niet is ingesteld, is de standaard-TTL-waarde voor een socket 32.

Het instellen van deze eigenschap op een TCP-socket (Transmission Control Protocol) wordt genegeerd door de TCP/IP-stack als er een geslaagde verbinding tot stand is gebracht met behulp van de socket.

Als u een SocketExceptionontvangt, gebruikt u de SocketException.ErrorCode eigenschap om de specifieke foutcode te verkrijgen. Nadat u deze code hebt verkregen, raadpleegt u de Windows Sockets versie 2 API-foutcode documentatie voor een gedetailleerde beschrijving van de fout.

Van toepassing op