I am developing a TCP client with Python. My problem comes when I want to send the structure to the server, I use the method struct.pack() to send and struct.unpack() to receive. I have my own protocol over TCP, with some headers which I already know the length of them, but of course, I don't know the length of the body, How could I pack all the fields without knowing the length of the body? Here is an example:
Request to the server:
pack('!BBBBHHII', P2P_h.version, P2P_h.ttl, P2P_h.msgType, P2P_h.reserved, P2P_h.sendPort, P2P_h.payloadLength, P2P_h.ipSrc, P2P_h.messageId)
Response from the server:
queryHit = unpack ("!BBBBHHII", queryResponse)
In those examples there are just the headers, I mean, the fields that I already know their length, how could I add the body field?