Compartir vía


Socket.NoDelay Propiedad

Definición

Obtiene o establece un Boolean valor que especifica si la secuencia Socket usa el algoritmo nagle.

public:
 property bool NoDelay { bool get(); void set(bool value); };
public bool NoDelay { get; set; }
member this.NoDelay : bool with get, set
Public Property NoDelay As Boolean

Valor de propiedad

false Socket es si usa el algoritmo nagle; de lo contrario, truees . El valor predeterminado es false.

Excepciones

Se produjo un error al intentar acceder Socketa .

Ejemplos

En el ejemplo de código siguiente se muestra el uso de la NoDelay 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 algoritmo nagle está diseñado para reducir el tráfico de red, lo que provoca que el socket almacene en búfer paquetes pequeños y, a continuación, combine y envíelos en un paquete en determinadas circunstancias. Un paquete TCP consta de 40 bytes de encabezado más los datos que se envían. Cuando se envían paquetes pequeños de datos con TCP, la sobrecarga resultante del encabezado TCP puede convertirse en una parte significativa del tráfico de red. En redes muy cargadas, la congestión resultante de esta sobrecarga puede provocar pérdidas de datagramas y retransmisiones, así como un tiempo de propagación excesivo causado por la congestión. El algoritmo nagle impide el envío de nuevos segmentos TCP cuando llegan nuevos datos salientes del usuario si alguno de los datos transmitidos previamente en la conexión sigue sin conocerse.

La mayoría de las aplicaciones de red deben usar el algoritmo nagle.

Establecer esta propiedad en un socket del Protocolo de datagramas de usuario (UDP) no tendrá ningún efecto.

Se aplica a