This week I was working on a project and ended up with a simple problem. I had to send a couple of messages using UDP protocol, between a .NET and an Android application and it happened that I found out a great way to do that by playing with some XML…
My problem was about sending a couple of messages through the internet using UDP protocol and as you know, when you work with Sockets you must setup a byte array and send it while the other part will get it as a byte array as well.
And you would like to convert an object in a byte array. It is so simple, I coded two methods one for convert in a byte array and another one to convert from a byte array in an object back.
That’s it! I told it was so simple, I didn’t realize it was so simple before reading a little bit more about XmlSerializer. I totally recommend it guys!
Before finishing up this tutorial, let’s run a single test to prove that it worked swell.