Do you have a test, e.g. unittest, that checks for serialization and deserialization without any network involvement?

Do you receive datagrams?

Any reason you discard all datagrams but the last?

Your stream operators aren't used so they can't really be the problem.

If your goal is to use them in a later stage of your program, you should probably rethink using a hard coded magic number (40) when looping :-)

Cheers,
_