-
sending JPGs in pieces?
Hi,
In C, I want to take a JPG image (<10KB) and send it to another machine on my network. I just started the code yet so I'm wondering if it'll work or if someone has done something similar before I encounter any serious problems. I want to break the JPG into ~1KB pieces and send them periodically.
My plan is to open the JPG into a buffer then on my write() I'll specify the count bytes as 1000. Can I do this with a JGP image or do I have to go about it a different way?
Thanks,
Chris
-
Of course you can do this -- that's how network programming works. The fact you are sending an image file is irrelevant (it doesn't matter what data you send across).
You can use write() call to send across the network on Linux machines, but if you want to be portable to other OS's, then you should look into using send() instead.
-
Ok so I have started with my coding but I'm puzzled on writing the receiver. I have to use UDP for this so I'm using sendto() and recvfrom(), the sender loops through the file and sends out packets in my 1000 byte size but how am i supposed to know when the end of the packets has arrived? recvfrom() returns bytes received so should I check my receiving buffer at location buffer[n-1] for NULL or \r\n?
Thanks,
Chris
-
You cannot do it by checking for a particular character such as '\0' or '\r\n' or '\n' etc because ALL char values are legal inside of a jpeg. It will have 0's and 10's and 15's and 27's in it, etc.
So either you just presume when it's done or (my recommendation) you send the size of the file first.
-
Right, I made the changes. thanks
Chris