Partager via


Socket.SendBufferSize Propriété

Définition

Obtient ou définit une valeur qui spécifie la taille de la mémoire tampon d’envoi du Socket.

public:
 property int SendBufferSize { int get(); void set(int value); };
public int SendBufferSize { get; set; }
member this.SendBufferSize : int with get, set
Public Property SendBufferSize As Integer

Valeur de propriété

Qui Int32 contient la taille, en octets, de la mémoire tampon d’envoi. La valeur par défaut dépend du système d’exploitation.

Exceptions

Une erreur s’est produite lors de la tentative d’accès au socket.

Il Socket a été fermé.

La valeur spécifiée pour une opération de jeu est inférieure à 0.

Exemples

L’exemple de code suivant illustre l’utilisation de la SendBufferSize propriété.

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("");
}

Remarques

Une plus grande taille de mémoire tampon peut retarder la reconnaissance des difficultés de connexion. Envisagez d’augmenter la taille de la mémoire tampon si vous transférez des fichiers volumineux ou que vous utilisez une connexion à bande passante élevée et à latence élevée (par exemple, un fournisseur haut débit satellite).)

S’applique à