Socket.NoDelay Socket.NoDelay Socket.NoDelay Socket.NoDelay Property

定義

ストリーム Socket が Nagle アルゴリズムを使用するかどうかを指定する Boolean 値を取得または設定します。Gets or sets a Boolean value that specifies whether the stream Socket is using the Nagle algorithm.

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

プロパティ値

Socket が Nagle アルゴリズムを使用する場合は false。それ以外の場合は truefalse if the Socket uses the Nagle algorithm; otherwise, true. 既定値は、false です。The default is false.

例外

Socket へのアクセスを試みているときにエラーが発生しました。An error occurred when attempting to access the Socket.

次のコード例は、の使用を示します、NoDelayプロパティ。The following code example demonstrates the use of the NoDelay property.

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 = gcnew 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 {0}", 
        tcpSocket->ExclusiveAddressUse);
    Console::WriteLine("  LingerState {0}, {1}", 
        tcpSocket->LingerState->Enabled,
        tcpSocket->LingerState->LingerTime);
    Console::WriteLine("  NoDelay {0}",
        tcpSocket->NoDelay);
    Console::WriteLine("  ReceiveBufferSize {0}", 
        tcpSocket->ReceiveBufferSize);
    Console::WriteLine("  ReceiveTimeout {0}",
        tcpSocket->ReceiveTimeout);
    Console::WriteLine("  SendBufferSize {0}",
        tcpSocket->SendBufferSize);
    Console::WriteLine("  SendTimeout {0}",
        tcpSocket->SendTimeout);
    Console::WriteLine("  Ttl {0}",
        tcpSocket->Ttl);
    Console::WriteLine("  IsBound {0}",
        tcpSocket->IsBound);
    Console::WriteLine("");
}
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 {0}", 
				tcpSocket.ExclusiveAddressUse);

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

	Console.WriteLine("  NoDelay {0}", 
                                              tcpSocket.NoDelay);

	Console.WriteLine("  ReceiveBufferSize {0}", 
				tcpSocket.ReceiveBufferSize);

	Console.WriteLine("  ReceiveTimeout {0}", 
				tcpSocket.ReceiveTimeout);

	Console.WriteLine("  SendBufferSize {0}", 
				tcpSocket.SendBufferSize);

	Console.WriteLine("  SendTimeout {0}", 
                                              tcpSocket.SendTimeout);

	Console.WriteLine("  Ttl {0}", 
                                              tcpSocket.Ttl);

                      Console.WriteLine("  IsBound {0}", 
                                              tcpSocket.IsBound);

	Console.WriteLine("");
}

注釈

Nagle のアルゴリズムは、小さなパケット バッファーを結合し、特定の状況で 1 つのパケットで送信するソケットでのネットワーク トラフィックの削減に設計されています。The Nagle algorithm is designed to reduce network traffic by causing the socket to buffer small packets and then combine and send them in one packet under certain circumstances. TCP パケットは、header、および送信されるデータの 40 バイトで構成されます。A TCP packet consists of 40 bytes of header plus the data being sent. 小さなデータ パケットを TCP で送信されると、TCP ヘッダーに起因するオーバーヘッドは、ネットワーク トラフィックのかなりの部分になります。負荷の高いネットワークでは、このオーバーヘッドの結果の輻輳が失われたデータグラムと再送信、ほかの輻輳による過剰な伝達時間が発生できます。When small packets of data are sent with TCP, the overhead resulting from the TCP header can become a significant part of the network traffic.On heavily loaded networks, the congestion resulting from this overhead can result in lost datagrams and retransmissions, as well as excessive propagation time caused by congestion. Nagle のアルゴリズムでは、送信の新しい TCP segmentswhen 新しい previouslytransmitted データ接続での受信確認されていないままの場合、ユーザーから到着するデータの送信を禁止します。The Nagle algorithm inhibits the sending of new TCP segmentswhen new outgoing data arrives from the user if any previouslytransmitted data on the connection remains unacknowledged.

ネットワーク アプリケーションの大部分は、Nagle アルゴリズムを使用する必要があります。The majority of network applications should use the Nagle algorithm.

ユーザー データグラム プロトコル (UDP) のソケットにこのプロパティを設定しても影響します。Setting this property on a User Datagram Protocol (UDP) socket will have no effect.

適用対象