Socket.Ttl Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene o establece un valor que especifica el valor de período de vida (TTL) de los paquetes de Protocolo de Internet (IP) enviados por .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
Valor de propiedad
Valor TTL.
Excepciones
El valor de TTL es un número negativo.
El socket no está en las InterNetwork familias o InterNetworkV6 .
Error al intentar acceder al socket. Este error también se devuelve cuando se intentó establecer TTL en un valor superior a 255.
Se Socket ha cerrado.
Ejemplos
En el ejemplo de código siguiente se muestra el uso de la Ttl propiedad .
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("");
}
Comentarios
El valor TTL indica el número máximo de enrutadores que el paquete puede atravesar antes de que el enrutador descarte el paquete y se devuelve un mensaje de error "TTL superado" del Protocolo de mensajes de control de Internet (ICMP) al remitente.
El valor de TTL se puede establecer en un valor de 0 a 255. Cuando no se establece esta propiedad, el valor TTL predeterminado para un socket es 32.
Si la pila TCP/IP establece esta propiedad en un socket del Protocolo de control de transmisión (TCP) se omite si se ha establecido una conexión correcta mediante el socket.
Si recibe un SocketException, use la SocketException.ErrorCode propiedad para obtener el código de error específico. Después de obtener este código, consulte la documentación del código de error de la API de Windows Sockets versión 2 para obtener una descripción detallada del error.