1

I am making a chat client that receives structs of info from the server over a UDP socket in varying amounts. Each one of these structs starts with a header that tells the client what type of struct it is. Is it possible to use recvfrom to retrieve the entire struct, no matter what the size is, and then cast it to whatever struct I need based on the header, or do I first have to read the header, determine the struct, and then read in the struct piece by piece?

4

1 に答える 1

3

UDP パケットは、完全なデータグラムとしてのみ受信できます。recvfromメッセージに十分な大きさのバッファを使用して、適切にキャストする必要があります。

于 2012-10-27T20:14:53.253 に答える