carlk Posted March 12, 2010 Posted March 12, 2010 Hi, i'm pretty a noob in .NET and try to serialize a class and send it into an UDP packet. I use the udpClient class on my client and server sides and I can get an array of byte to transfert from one to another. What I don't know is how to serialize my object (which basically consist of 3 strings and 1 dictionnary). that object has the name "myCustomClassInstance" in the following example code. (-->this also means that its size is variable and that I will have to check that the size of my serialized object is under the [MTU minus header] size. but that's another problem.) For the moment I get to serialize my message by using a binaryformater then send it: Dim mySimpleFormatter As BinaryFormatter = New BinaryFormatter() Dim myStream As New MemoryStream() mySimpleFormatter.Serialize(myStream, myCustomClassInstance) myUdpClient.Send(mystream, mystream.Length) but on the listining side, the udpClient.receive(myIPEndPoint) method returns a byte array. Then, I don't get how to convert back that byte array in an instance of the same type of my "myCustomClassInstance" object. Thanks for the help and advices. Quote
Administrators PlausiblyDamp Posted March 12, 2010 Administrators Posted March 12, 2010 On the receiving end have you tried creating as memory stream over the byte array and the de-serializing from this memory stream? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
carlk Posted March 12, 2010 Author Posted March 12, 2010 yeah I was kind of mixed up because the BinaryFormatter..::.Deserialize Method (Stream) takes a stream as parameter and not a byte() but I've found that tutorial http://devhood.com/tutorials/tutorial_details.aspx?tutorial_id=448 with a written example and I now understand and make that work. now I don't understand why I can send a byte array up to 65508 Bytes over the network, because i thought the MTU was generally 1492 Bytes. Quote
passel Posted March 16, 2010 Posted March 16, 2010 If you use wireshark, or some other tool to see the packets transferred, you will see a bunch of fragmented, or partial UDP packets. A large array of bytes has to be broken down into multiple UDP packets since, as you say, any one packet will be limited to the MTU size. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.