I am writing a client for a P2P application per minute, and the specification for the protocol says that the header for each packet should have each field with a specific byte length:
Version: 1 Byte Type: 1 Byte Length: 2 Bytes And then the data
I have a way to pack and unpack the header fields (I think) as follows:
packed = struct.pack('cch' , '1' , '1' , 26)
This creates a header for a packet with a data length of 26, but when it comes to unpacking the data, I'm not sure how to do this after receiving the rest of the data. To unpack, we need to know the size of all the fields, if I do not miss something? I think in order to pack the data, I would use the "cch26s" format indicator, meaning:
1 Byte char 1 Byte char 2 Byte short 26 Byte char array
But how can I unpack the data when I do not know how much data will be included in the package?
source share