The simplest solution is to create a class MyMessage and mark it with Serializable attribute,
Here:
[Serializable]
class MyMessage
{
// Put all your Data here
}
Serialize this class to MemoryStream,
Send the bytes of MemoryStream to the NetWorkStream.........
On The other Side, Get those bytes and Reconstruct the Message from the bytes using Deserialization,
See, this Namespace:
System.Runtime.Serialization.*........
And Specifically see BinaryFormatter class...
Make sure to Seperate the logic of Serialization/Deserialization in a single seperate dll.. And use it on both side,, Client and Server to work fine. Otherwise you'll get AssemblyNotFound Exception or something like that.
If you need any more detail or help, Feel Free to Write Again.
Best Regards,
Rizwan
|