gpt4 book ai didi

c - 在 UDP 套接字上使用 write()/read()?

转载 作者:IT王子 更新时间:2023-10-29 00:26:35 25 4
gpt4 key购买 nike

根据手册页:

The only difference between send() and write(2) is the presence of flags. With a zero flags argument, send() is equivalent to write(2). Also, the following call send(sockfd, buf, len, flags); is equivalent to sendto(sockfd, buf, len, flags, NULL, 0);

The recv() call is normally used only on a connected socket (see connect(2)) and is identical to recvfrom() with a NULL src_addr argument.

此外,如果我没记错(无法在手册页中找到它),recv with flags == 0 等同于 read (类似于writesend)。


所以:

  • 这是否意味着在 UDP 套接字上使用 read 完全没问题(如果我不需要 src_addr)?
  • 有没有办法在 UDP 套接字上使用 write(因为现在我在 sendtodest_addr 参数中设置了目标地址)?

最佳答案

  • 如果您不需要源地址,则在 UDP 套接字上使用 read() 非常好。
  • 如果您connect() UDP 套接字到目标,您可以使用write()

关于c - 在 UDP 套接字上使用 write()/read()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26909982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com