I have a similar problem, but I can withdraw images with packets lost.
I solved the problem making following steps:
1. Increasing the socket buffer size as said Pascal-78
2. In the receiver part I made a separate thread that only receives packets
3. Maintain the link live by sending back an acknowledge command every time I receive a command
4. Using select() with a timeout between 10 and 500 microseconds to look for a packet before reading it
5. As my soultion must work also in linux I made following command to allow increase the socket size:
sudo sysctl -w net.core.rmem_max=myMaxImagesize*2
6. I wrote at console a message every time data arrives, but unfortunately windows provokes a great delay writting at console. I solved that by writting this code lines at the beginning of the main() to increase console buffer:
#ifndef __linux__ //Introduce this code at the beginning of main() to increase a lot the speed of cout in windows:
char buf[4000]; setvbuf(stdout, buf, _IOFBF, sizeof buf);
#endif