Receiving a part of packet via recvfrom (UDP)

后端 未结 2 1116
無奈伤痛
無奈伤痛 2020-12-09 13:39

I\'m trying to receive a part of a packet via recvfrom. It actually works like this:

recvfrom(sockfd, serialised_meta, 12, flags, src_addr, addrlen);
recvfro         


        
相关标签:
2条回答
  • 2020-12-09 14:22

    UDP isn't a "stream" protocol... once you do the initial recvfrom, the remainder of the packet is discarded. The second recvfrom is awaiting the next packet...

    0 讨论(0)
  • 2020-12-09 14:31

    UDP operates on messages, not streams like TCP does. There is a 1-to-1 relationship between sendto() and recvfrom() when using UDP. There is no option to receive partial data in UDP, it is an all-or-nothing type of transport. You have to recvfrom() the entire BUFLEN+12 message in one go, then decide whether you are going to actually use it or not. That is just the way UDP works.

    0 讨论(0)
提交回复
热议问题