TcpClient.NoDelay文档状态:
Gets or sets a value that disables a delay when send or receive buffers are not full.
但是,不清楚这是否仅适用于设置为
true
后写入的数据。 ,或已写入并正在等待的数据。 IE。 当缓冲区中有数据时 NoDelay
然后设置为 true
,会不会立即发送缓冲区中的数据?
最佳答案
When there's data in the buffer and NoDelay is then set to true, will the data in the buffer be sent immediately?
号
它在下一个
Send
上被评估有有效数据。您可以通过
NoDelay = true
验证其次是 Send
有几个字节。或设置
NoDelay = true
无需调用 Send
之后,您应该不会看到任何变化。我使用 Wireshark 进行了验证,但可以使用您喜欢的任何数据包检查工具。
TcpClient
只是 Socket
周围的薄包装,所以你可以使用 Socket.NoDelay
以同样的方式。套接字选项由此设置 method调用
setsockopt
这是 native code :errorCode = UnsafeNclNativeMethods.OSSOCK.setsockopt(
m_Handle,
optionLevel,
optionName,
ref optionValue,
sizeof(int));
在这种情况下设置的实际选项是 TCP_NODELAY .
关于c# - TcpClient.NoDelay 会影响已经写入的数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65812433/