Will TcpClient.NoDelay affect already written data?

When there's data in the buffer and NoDelay is then set to true, will the data in the buffer be sent immediately?

No.

It gets evaluated on the next Send with valid data.

You can verify with NoDelay = true followed by Send with a few bytes.

Or set NoDelay = true without any call to Send after and you should see no change.

I verified using Wireshark, but use whatever packet inspection tool you prefer.


TcpClient is just a thin wrapper around Socket, so you can use Socket.NoDelay the same way.

Socket options are set by this method calling setsockopt which is native code:

errorCode = UnsafeNclNativeMethods.OSSOCK.setsockopt(
    m_Handle,
    optionLevel,
    optionName,
    ref optionValue,
    sizeof(int));

The actual option being set in this case is TCP_NODELAY.