PDA

View Full Version : Splitting data so it fits into datagrams



toratora
27th April 2007, 14:49
Hi

I want to send pics over a network using udpsocket. The problem is that I don't know how to split my data so that it fits into the maximum datagram size that this class admits. Any suggestions?

(What I have now is an IplImage (the image format from the OpenCV libraries). In the future it will be probably substituted by a encoded picture in H263, but I guess the problem is the same.

Thanks...

high_flyer
27th April 2007, 15:11
You mean something along the lines of:


for(int i=0;i<imageSize; i++)
{
if(imageSize-i > datagramSize)
memcopy(p_datagram,p_image+i,datagramSize);
else memcopy(p_datagram,p_image+i,imageSize-i);
//send datagram
}

wysota
27th April 2007, 15:40
There is one problem here - datagrams can be received in different order (or even lost completely) than they were sent, so it could be useful to include information about which octets of the file are transmitted in the datagram. Then you'll be able to assemble the image back on the target host properly. Also provide some kind of feedback in a form of positive or negative acknowledgements from the target host.

toratora
27th April 2007, 17:17
Thanks for the reply

Ya, that's the problem, the order is key.

That's why I was asking, in case there's something on Qt that can do that or any peace of code on the Internet anyone might know.

wysota
27th April 2007, 18:01
Simply invent and apply some kind of "header" to each datagram.