Easy Serialization of Network Packets
One of the tricks of network programming is simply sending all the data you need. Generally this involves one or more calls to a PacketWriter.Write method. For even a small packet you can wind up with three or four of these method calls everywhere you want to send a particular set of data. This quickly becomes time consuming and error prone. It’s even more annoying when you decide to change the data being sent and then have to update all the code that sends this data.
To this end, I’ve written up a simple PacketSerializer class. The PacketSerializer allows you to create a simple type and write the whole object out in one easy go, much like using a BinarySerializer or XmlSerializer. The difference being that this serializer writes and reads to and from a PacketWriter and PacketReader.
The entire class is given and described at the XNA Wiki article for it and is totally free for anyone to use, modify, or improve. Hopefully this will help out others as it has helped me with my network games.
Possibly Related Posts
(Automatically Generated)XmlSerializer Misconceptions Part 1
Creating Your Own XNB Files
IDictionary + XmlSerializer = Epic FAIL
Storage Device Management 2.0
Learning lambda expressions for XNA GS developers
