Michael's suggestion is correct but you will also have to make sure that the client and server both send/receive the entire image. This means either putting a delimiter at the end of the image data or sending a 4 byte 'image data size' value before the image data. This is a basic socket principle so you don't not send or not receive the entire application level message.