Thread: sending JPGs in pieces?

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    26

    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

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    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.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    26
    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

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Aug 2008
    Posts
    26
    Right, I made the changes. thanks

    Chris

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sending image
    By Ducky in forum Networking/Device Communication
    Replies: 23
    Last Post: 08-16-2009, 12:56 PM
  2. Sending data - line by line?
    By tuckker in forum C Programming
    Replies: 0
    Last Post: 02-21-2009, 09:31 PM
  3. the chess project
    By Hussain Hani in forum Projects and Job Recruitment
    Replies: 8
    Last Post: 05-28-2007, 02:33 AM
  4. a doubt about sending an array to a function
    By louis_mine in forum C Programming
    Replies: 13
    Last Post: 05-14-2005, 11:50 PM
  5. need help with sending file
    By finnepower in forum Networking/Device Communication
    Replies: 12
    Last Post: 03-20-2005, 01:12 PM