在发送数据包的时候如果启用Nagle算法的话(默认是启用),那么连续发送小的数据时接收方收到的就可能是一个大包,这样的话接收端处理接收的数据就很麻烦,所以我想把Nagle算法禁用。我的代码:BOOL bValue = TRUE;
bValue = psockclt->SetSockOpt(TCP_NODELAY, &bValue, sizeof(BOOL));
TRACE("%d", bValue);bValue返回true但是发送时还是会合并后再发送,这是为什么?
bValue = psockclt->SetSockOpt(TCP_NODELAY, &bValue, sizeof(BOOL));
TRACE("%d", bValue);bValue返回true但是发送时还是会合并后再发送,这是为什么?
The TCP_NODELAY option is specific to TCP/IP service providers. The Nagle algorithm is disabled if the TCP_NODELAY option is enabled (and vice versa). The process involves buffering send data when there is unacknowledged data already "in flight" or buffering send data until a full-size packet can be sent. It is highly recommended that TCP/IP service providers enable the Nagle Algorithm by default, and for the vast majority of application protocols the Nagle Algorithm can deliver significant performance enhancements. However, for some applications this algorithm can impede performance, and TCP_NODELAY can be used to turn it off. These are applications where many small messages are sent, and the time delays between the messages are maintained. Application writers should not set TCP_NODELAY unless the impact of doing so is well-understood and desired because setting TCP_NODELAY can have a significant negative impact on network and application performance.
s,
IPPROTO_TCP1, // here
TCP_NODELAY,
&bValue,
sizeof(BOOL)
);
在调用SetSockOpt时我改成了
BOOL bValue = TRUE;
bValue = psockclt->SetSockOpt(TCP_NODELAY, &bValue, sizeof(BOOL), IPPROTO_TCP);
TRACE("%d", bValue);
但还是不行,唉,郁闷!!!
ding根据微软的故障修复原则:把程序关闭,然后再次启动程序;如果故障依旧,应该把电脑关闭,然后再次启动电脑!
哈哈!
其实我也想知道答案!!
期盼高手!
你得把接收端的Socket缓冲区设成0,否则系统会先把收到的数据放入Socket缓冲区,接收时才拷入你的接收缓冲区.BOOL bValue = TRUE;
BOOL bRet = psockclt->SetSockOpt(TCP_NODELAY, &bValue, sizeof(BOOL));