If you want send packet immediately. Try this
int flag = 1;
int result = setsockopt(sock, /* socket affected */
IPPROTO_TCP, /* set option at TCP level */
TCP_NODELAY, /* name of option */
(char *) &flag, /* the cast is historical
cruft */
sizeof(int)); /* length of option value */
if (result < 0)
... handle the error ...
leo friendly note: TCP_NODELAY is in <netinet/tcp.h>
本文介绍了一种在TCP协议中立即发送数据包的方法。通过设置socket选项TCP_NODELAY,可以禁用Nagle算法,实现数据包即时发送。适用于需要低延迟的应用场景。
209

被折叠的 条评论
为什么被折叠?



