So why not send the size of the data your sending before sending the actual image data? Then you know the size you are expecting.