views:

134

answers:

1

I am writing a Sivlerlight Chat application using Sockets and the DataContractSerializer.

I have a class hierarchy of serializable objects with the definitions shared between the Silverlight Client and the C# Server.

When a buddy logs on they send a message to the server and if they are verified they are sent an acknowledgment followed by several messages which tell them who else is online (and some other messages as well). The client then waits on the socket and ready bytes off of it. It will then try to deserialize the objects off of the resulting byte stream. However because the server has sent several messages the byte stream will contain the xml for more than one element and when it is deserialized a Multiple root exception is thrown.

What is the standard solution for deserializing a stream of objects off of a Socket using the DatacontractSerializer?

Thanks

A: 

I found a solution though it seems a little hacky.

Because the data contract serializer produces XML i decided just to write an additional '\0' byte into the stream after each object. Then on the end i just takewhile(b => b != 0) from the byte stream to find the objects. This works so far but it seems like theres probably an edge case im not aware of.

...

luke