Byte Array in C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • prabhu.pravin@gmail.com

    #1

    Byte Array in C

    I want to Transmit Data using Using Socket Programming in C. The only
    Problem is that the data contains a lot of NULL characters in between
    (it is an JPEG image data).so if I populate a Char array with the data
    and try transmitting using send() only a part of the data is sent,
    since null character is taken as a end-of-line in C.
    Is there any way that send() can ignore the null character and transmit
    the entire data in the buffer.

  • Alex Fraser

    #2
    Re: Byte Array in C

    <prabhu.pravin@ gmail.com> wrote in message
    news:1121334009 .850448.188620@ g14g2000cwa.goo glegroups.com.. .[color=blue]
    > I want to Transmit Data using Using Socket Programming in C. The only
    > Problem is that the data contains a lot of NULL characters in between
    > (it is an JPEG image data).so if I populate a Char array with the data
    > and try transmitting using send() only a part of the data is sent,
    > since null character is taken as a end-of-line in C.[/color]

    '\0' is not "taken as end-of-line in C". The string functions use it to
    indicate the end of a string.

    There are no sockets and no send() function in standard C. However, if you
    read the documentation for your system's send() function I am sure you will
    find no mention of any significance of characters with the any particular
    values.

    For help with socket programming you should ask in a platform-specific
    newsgroup.

    Alex


    Comment

    • Chris Croughton

      #3
      Re: Byte Array in C

      On 14 Jul 2005 02:40:09 -0700, prabhu.pravin@g mail.com
      <prabhu.pravin@ gmail.com> wrote:
      [color=blue]
      > I want to Transmit Data using Using Socket Programming in C. The only
      > Problem is that the data contains a lot of NULL characters in between
      > (it is an JPEG image data).so if I populate a Char array with the data
      > and try transmitting using send() only a part of the data is sent,
      > since null character is taken as a end-of-line in C.
      > Is there any way that send() can ignore the null character and transmit
      > the entire data in the buffer.[/color]

      (a) Sockets are not part of the C standard, and are therefore off topic
      in comp.lang.c, try a newsgroup relevant to your operating system,
      for example:

      comp.unix.progr ammer
      comp.os.linux.n etworking
      comp.os.ms-windows.apps.wi nsock.misc
      comp.os.ms-windows.network ing.tcp-ip

      (b) A null character is not "taken as a end-of-line in C", the end of
      line character is '\n'. A null character is use to indicate the end
      of a string by the string functions and is otherwise treated as
      data.

      (c) [OFF TOPIC]
      The send() function in Unix (and as far as I know Windows Sockets)
      sends as many characters as its parameter specifies, it doesn't
      handle null characters (or any other character value) specially.
      Perhaps you are trying to use strlen() to determine the length? Or
      perhaps the receiving program is treating the received data as a
      string?
      [/OFF TOPIC]

      Chris C

      Comment

      • Stephan Beyer

        #4
        Re: Byte Array in C

        > Is there any way that send() can ignore the null character and transmit[color=blue]
        > the entire data in the buffer.[/color]

        Keep the length in a variable and try write() from unistd.h (on
        POSIX-compatible systems)

        Stephan

        --
        Stephan Beyer, PGP 0xFCC5040F, IRC sbeyer (seebyr, bseyer)

        -----BEGIN PGP SIGNATURE-----
        Version: GnuPG v1.4.1 (GNU/Linux)

        iD8DBQFC1nWVbt3 SB/zFBA8RArVGAJ9ku z5TPDCcV2bfF2qq 8o6w7YvyTgCeKuO R
        bRG27vp78fjZkOG tjVuIiW4=
        =D3h6
        -----END PGP SIGNATURE-----

        Comment

        • Emmanuel Delahaye

          #5
          Re: Byte Array in C

          prabhu.pravin@g mail.com wrote on 14/07/05 :[color=blue]
          > I want to Transmit Data using Using Socket Programming in C. The only
          > Problem is that the data contains a lot of NULL characters in between[/color]

          Of course, you meant 'nul characters'...
          [color=blue]
          > (it is an JPEG image data).so if I populate a Char array with the data[/color]

          'Char' is not a standard C type. You meant 'char'...
          [color=blue]
          > and try transmitting using send() only a part of the data is sent,
          > since null character is taken as a end-of-line in C.[/color]

          What ? I guess that BSD-socket send() function (which is not part of
          the C-language) has an address/ length interface. If it's true, the
          zeros are just like another data. If not, use another function
          (sendto() etc. read the manual).

          BTW, there is no relationship between the nul character 0 and the end
          of line.
          [color=blue]
          > Is there any way that send() can ignore the null character and transmit
          > the entire data in the buffer.[/color]

          I'm quite sure it does. You must have some problem before... (like
          using strcpy() instead of memcpy() for binary streams...

          BTW, the stream should be implemented by an array of unsigned char.

          --
          Emmanuel
          The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
          The C-library: http://www.dinkumware.com/refxc.html

          ..sig under repair

          Comment

          • Keith Thompson

            #6
            Re: Byte Array in C

            Stephan Beyer <s-beyer@gmx.net> writes:[color=blue][color=green]
            >> Is there any way that send() can ignore the null character and transmit
            >> the entire data in the buffer.[/color]
            >
            > Keep the length in a variable and try write() from unistd.h (on
            > POSIX-compatible systems)[/color]

            Neither send() or write() is topical here, since they're both
            non-standard functions. Having said that, several others have pointed
            out that send() does not treat null characters specially.

            --
            Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
            San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
            We must do something. This is something. Therefore, we must do this.

            Comment

            • SM Ryan

              #7
              Re: Byte Array in C

              prabhu.pravin@g mail.com wrote:
              # I want to Transmit Data using Using Socket Programming in C. The only
              # Problem is that the data contains a lot of NULL characters in between
              # (it is an JPEG image data).so if I populate a Char array with the data
              # and try transmitting using send() only a part of the data is sent,
              # since null character is taken as a end-of-line in C.
              # Is there any way that send() can ignore the null character and transmit
              # the entire data in the buffer.

              Use a write function that includes an explicit data length, like stdio
              fwrite or unix write, instead of write function that looks for terminating
              byte like fputs.

              A unix send(2) function has a buffer size argument. Are you using strlen
              to decide the current buffer size or are keeping track of how much you
              put in?

              --
              SM Ryan http://www.rawbw.com/~wyrmwif/
              Quit killing people. That's high profile.

              Comment

              Working...