Image transwering using CAsyncsoc
-
Hi this is ramu I got a problem in transwering the image buffer. Actually the problem is at receiving side. The receive statement not receiving the whole data sent. Some body advised to send the length as a heder first and get it at the client side and make a loop untill the whole length is received. But i dont know how to make the length as heade in serverside to send and how to put the receive statement in loop. So please some body help me out in this problem. Thank you. Ramu
-
Hi this is ramu I got a problem in transwering the image buffer. Actually the problem is at receiving side. The receive statement not receiving the whole data sent. Some body advised to send the length as a heder first and get it at the client side and make a loop untill the whole length is received. But i dont know how to make the length as heade in serverside to send and how to put the receive statement in loop. So please some body help me out in this problem. Thank you. Ramu
There are several ways. An easy way could be by sending i.e. an unsigned long (if has the capacity needed) as the first data. Kind of like this: Sending side
unsigned long datalength = imageLength; Send(&datalength, sizeof(unsigned long)); while(moreDataToSend) { send(data); }
At the receiving side (assuming that the Read function returns the number of bytes read from the socket):unsigned long receivedDataLength; Read(&receivedDataLength, sizeof(unsigned long)); unsigned long receivedBytes = 0L; while(receivedBytes < receivedDataLength) { receivedBytes += (unsigned long) Read(buffer, sizeof(buffer); // Do something with buffer }
If an unsigned long isn't enough, the use some other variable type. Just make sure it's the same on both sides.