Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我以这种方式检查 recvfrom() 的返回值: while ((n = recvfrom(sockfd, buf, BUF_SIZE, 0, NULL, NULL)) > 0) 我尝试关闭发送方的套接字,但 recvfrom() 仍然阻塞。手册说,当对等方执行有序关闭时,recvfrom() 返回 0。关闭 UDP 套接字是没用的,对吧? 任何答案将不胜感激。谢谢。
while ((n = recvfrom(sockfd, buf, BUF_SIZE, 0, NULL, NULL)) > 0)
的返回值recvfrom是接收到的数据报中的用户数据量。UDP 可接受的返回值0:这并不意味着对端已关闭连接,因为写入长度为 0 的数据报是可以接受的。
recvfrom
0