How to read UDP packet with variable length in C

后端 未结 4 1447
天命终不由人
天命终不由人 2021-01-13 15:34

I\'m sending a C struct over UDP

struct packet{
    int numInt;
    int* intList; //malloc\'ed as (sizeof(int)*numInt)
}

It will be seriali

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-13 15:59

    I'm pretty sure recvfrom will read up to as many bytes as is told to it by its 3rd argument, len. If there are fewer bytes available, it will return what is there. If there are more, it will return up to len bytes. You may have to make additional calls to obtain all the data your are expecting.

提交回复
热议问题