0

I am trying to bind Sound and Image Sequence Data through ArrayList in order to get it synchronized and serializing it through Binary formatter to be send over Network stream. The Server end threw an exception:

THE STREAM CAN NOT SUPPORT SEEK OPERATION.

What should I have to do in order to sync Objects to be sent over a single Network stream Instance

2 Answers 2

3

TCP is stream based and not message based (as UDP is). That means that there is no telling when a message starts or ends. TCP only guarantees that all bytes are received and in the correct order. It does not guarantee that everything sent with one Send() will be received with one Receive().

Hence you need to specify some kind of message identification mechanism. In this case, a header is the way to go as Jon suggested.

However, you need to understand that the entire header might not be received at once. And that two messages might arrive at once. So you need to parse the received buffer before sending anything to the BinaryFormatter for deserialization.

Sign up to request clarification or add additional context in comments.

2 Comments

I have two Objects Let say A and B......A containing Mp3 frames and B containing Bitmap Compress Images..I was binding the objects in an ArrayList as it can contain Objects in it.Then I am Serializing it using BinaryFormatters and Sending it Over Network Stream.But it threw an exception that I have listed above
It's because everything haven't arrived yet. You need to build a byte[] buffer manually (or a MemoryStream). You can not just try to deserialize the networkstream.
2

I would split each object you want to send out into a separate "message" where a message consists of (say) 4 bytes indicating the body length, and then the body itself.

When you want to send a serialized object, you serialize to a byte array, write out the length, then write out the data.

At the server side, you read the length, read that much data into a byte array, then deserialize from that message. The incoming stream is only used to read messages, not objects.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.