This documentation is archived and is not being maintained.

TcpClient.NoDelay Property

Gets or sets a value that disables a delay when send or receive buffers are not full.

[Visual Basic]
Public Property NoDelay As Boolean
[C#]
public bool NoDelay {get; set;}
[C++]
public: __property bool get_NoDelay();
public: __property void set_NoDelay(bool);
[JScript]
public function get NoDelay() : Boolean;
public function set NoDelay(Boolean);

Property Value

true if the delay is disabled, otherwise false. The default value is false.

Remarks

When NoDelay is false, a TcpClient does not send a packet over the network until it has collected a significant amount of outgoing data. Because of the amount of overhead in a TCP segment, sending small amounts of data is inefficient. However, situations do exist where you need to send very small amounts of data or expect immediate responses from each packet you send. Your decision should weigh the relative importance of network efficiency versus application requirements.

Example

[Visual Basic, C#, C++] The following example enables the delay. It then checks the value of NoDelay to verify that the property was successfully set.

[Visual Basic] 
' Sends data immediately upon calling NetworkStream.Write.
tcpClient.NoDelay = True

' Determines if the delay is enabled by using the NoDelay property.
If tcpClient.NoDelay = True Then
   Console.WriteLine(("The delay was set successfully to " + tcpClient.NoDelay.ToString()))
End If

[C#] 
// Sends data immediately upon calling NetworkStream.Write.
tcpClient.NoDelay = true;

// Determines if the delay is enabled by using the NoDelay property.
if (tcpClient.NoDelay == true)
    Console.WriteLine ("The delay was set successfully to " + tcpClient.NoDelay.ToString ());


[C++] 
// Sends data immediately upon calling NetworkStream.Write.
tcpClient->NoDelay = true;

// Determines if the delay is enabled by using the NoDelay property.
if (tcpClient->NoDelay == true)
     Console::WriteLine(S"The delay was set successfully to {0}", __box(tcpClient->NoDelay));

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

TcpClient Class | TcpClient Members | System.Net.Sockets Namespace

Show: