BinaryStream send filesize

Hello,

i am converting a image to a memoryblock and create a binarystream out of that memoryblock.

p=myPic
mb=p.GetData(Picture.FormatJPEG,Picture.QualityMedium)
stream=New BinaryStream(mb)

In the first step i want to send the size of the binarystream as the first 2 bytes via tcp socket and read them back later in a DataAvailable event.

How do i add this to the binaryStream and how do i read it back later?

Thanks Marco

Don’t add it to the binarystream. Just send the bytes first over whatever socket you’re using.

That said, two bytes may not be enough as that’s only 65K. You might be better off using 3 or 4 so your code doesn’t need to change if the images get bigger.

On the receiving end, just expect the size first, read them, and then use the binarystream to read the remainder.