Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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.

Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...