Thread: Sending null-bytes over a socket?

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    16

    Sending null-bytes over a socket?

    Hi, I am coding a webserver, and I'm kinda stuck at the moment.

    The webserver perfectly sends text-based files to the client, but when I try to send files that has null-bytes (0x00) in them (like .PNG images), then then send() gets angry and stops the transmission at the null-byte.

    Any good way to tackle this?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Are you sure you're not doing something like "strlen(buffer)" to get the number of bytes to send?

    As far as I know, send() should be perfectly fine with whatever you like to send.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    send() doesn't care about the values.

    How are you determining the amount of data to be sent in the first place?
    Did you open the file in binary mode?
    Did you use fread() to read the data?
    Did you use the return result of fread() as the length for send() ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "Virtual Printer" or "Moving Printjobs"
    By extasic in forum Windows Programming
    Replies: 12
    Last Post: 06-30-2011, 08:33 AM
  2. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  3. addrinfo Structure Not Working
    By pobri19 in forum Networking/Device Communication
    Replies: 9
    Last Post: 10-22-2008, 10:07 AM
  4. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  5. Where do I initialize Winsock and catch messages for it?
    By Lithorien in forum Windows Programming
    Replies: 10
    Last Post: 12-30-2004, 12:11 PM