public Bitmap ReceiveImage() { int receivedPackages = 0; ImageBit image = Deserialize(client.Receive()); ImageBit[] arrStructs = new ImageBit[image.NumberBits]; arrStructs[image.CurrentBit] = image; int imageNumber = image.ImageNumber; receivedPackages++; while (true) { image = Deserialize(client.Receive()); if (imageNumber == image.ImageNumber) { receivedPackages++; arrStructs[image.CurrentBit] = image; if ((receivedPackages == (image.NumberBits)) && (imageNumber == image.ImageNumber)) { client.SendResponse(response); return(AssemblyBitmap(arrStructs, image.Size)); } } else { imageNumber = image.ImageNumber; arrStructs = new ImageBit[image.NumberBits]; arrStructs[image.CurrentBit] = image; receivedPackages = 1; } } }