MemoryBlock iOS picture

Hello, I am trying to send a simple picture to my iOS device.

this is how I am sending:
mb=myPIC.GetData(Picture.FormatJPEG,Picture.QualityHigh)
Binarydata=new BinaryStream(mb)

dim sendpic() as TCPSocket = window1.MainServerSocket.ActiveConnections

dim sock as ClientSocket
for i as integer = 0 to UBound(sendpic)  
  do Until binaryData.EOF
    sendpic(i).write(binarydata.Read(binarydata.Length)+chr(13)+chr(10))
  loop 
next

and on my iOS app this is how I try to create my picture (in event dataAvailable):

DIM data As MemoryBlock
data = me.ReadData(me.BytesAvailable)
DIM endofpacket As Integer

dim s as text = Xojo.Core.TextEncoding.utf8.ConvertDataToText(data,true)
endofpacket = s.IndexOf(text.FromUnicodeCodepoint(13)+text.FromUnicodeCodepoint(10))

while endofpacket>0 
  buffer.Append(data) //buffer is a MutableMemoryBlock
wend

if endofpacket=-1 then
  dim pic as iOSImage= iOSImage.FromData(buffer)
  p = ScaleImage(pic,d)
  Canvas1.Invalidate
end if

but this does not work.
could somebody point me into the right direction?