BSD 套接字 setockopt 选项可避免在下一次发送之前等待确认 [英] BSD sockets setsockopt option to avoid waiting for acknowledge before next send

查看:39
本文介绍了BSD 套接字 setockopt 选项可避免在下一次发送之前等待确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用专有的简单原始 TCP 协议通过以太网发送一些 KB 的数据.

I am trying to send some KBytes of data trough Ethernet with a proprietary simple raw TCP protocol.

标准 Windows 配置要求在返回确认数据包之前接收两 (2) 个数据包,除非您使用 TcpAckFrequency = 1 修改注册表,在这种情况下,收到的一个数据包足以发回确认,否则您将获得一个默认情况下,TcpDelAckTicks * 100 = 200 ms 之后的 ACK(这是另一个注册表项).如果我以小于 1460 字节的块发送数据,这是一个问题,因为每个块将在 200 毫秒后得到确认,并且发送方将在发送下一个数据包之前等待.一种解决方案是将数据分块发送大于 1460 字节,这样实际上会发送两个数据包并收到 ACK.

Standard Windows configuration requires two (2) packets received before returning an acknowledge packet, unless you modify the registry with TcpAckFrequency = 1, in which case one received packet is enough to send back the acknowledgement, or otherwise anyway you will get an ACK after TcpDelAckTicks * 100 = 200 ms by default (this is another registry key). This is a problem if I send the data in chunks of less than 1460 bytes, because each chunk will get an acknowledge after 200 ms, and the sender will wait that before sending the next packet. One solution is to send data in pieces bigger than 1460 bytes, so that two packets will be actually sent and ACK received.

但是,如果我想发送较小的数据包怎么办?有没有办法用setsockopt配置套接字,以便在发送下一个数据包之前不等待确认数据包?

But, what about if I want to send smaller packets? Is there a way to configure the socket with setsockopt for not waiting acknowledgment packets before sending the next packet?

非常感谢您.

推荐答案

在发件人处关闭 Nagle 算法.在 C 中,这是 TCP_NODELAY 选项.

Turn off the Nagle algorithm at the sender. In C this is the TCP_NODELAY option.

这篇关于BSD 套接字 setockopt 选项可避免在下一次发送之前等待确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆