Splitting data so it fits into datagrams
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...
Re: Splitting data so it fits into datagrams
You mean something along the lines of:
Code:
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
}
Re: Splitting data so it fits into datagrams
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.
Re: Splitting data so it fits into datagrams
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.
Re: Splitting data so it fits into datagrams
Simply invent and apply some kind of "header" to each datagram.