我注意到sendto 和recvfrom (UDP) 之间存在性能差异。我使用 WiFi 从服务器向客户端发送大约 100Kbytes(估计双向带宽约为 30Mb/s),发送时间约为 4-5 ms(具体取决于情况,但该值与理想值相当) ,3毫秒)。在客户端,接收时间要高出十到十五倍,比如50-60ms。我希望这两个耗时非常相似。有什么想法吗?
最佳答案
and the sending time is about 4-5 ms (it depends, but this value is comparable to the ideal one, 3ms)
30Mb/s(其中 b 表示位)大约(考虑 header 等)3 MB/s(其中 B 表示字节) 。传输 100kBytes 大约需要 30 毫秒。
sendto
在将所有数据写入发送机器网络堆栈的本地缓冲区后立即返回。 recv
显然必须等待数据传输,包括延迟和所有协议(protocol)层所需的内容。
关于c - sendto和recvfrom之间的性能差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17929018/