Assuming that in UDP, i know that packets i am receiving are 200 bytes each.
In C socket programming:
n = recvfrom(sockfd,mesg,1000,0,(struct sockaddr *)&cliaddr,&len);
if i define the buffersize as 1000. Does that mean i can received 5 packets each time?
Or i will only still get 1 packet and the remaining 800 bytes in my buffer are unused?
tks!
If you KNOW your packets will NEVER exceed 200 bytes, then there’s no need to declare your buffer any larger than 200 bytes.
Each recvfrom() will receive AT MOST one packet. Remaining packets are buffered by the stack. There is really no “performance penalty” from reading multiple packets in a “while()” loop.