Byte Array in C

P

prabhu.pravin

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.
 
A

Alex Fraser

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.

'\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
 
C

Chris Croughton

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.

(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.programmer
comp.os.linux.networking
comp.os.ms-windows.apps.winsock.misc
comp.os.ms-windows.networking.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
 
S

Stephan Beyer

Is there any way that send() can ignore the null character and transmit
the entire data in the buffer.

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)

iD8DBQFC1nWVbt3SB/zFBA8RArVGAJ9kuz5TPDCcV2bfF2qq8o6w7YvyTgCeKuOR
bRG27vp78fjZkOGtjVuIiW4=
=D3h6
-----END PGP SIGNATURE-----
 
E

Emmanuel Delahaye

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

Of course, you meant 'nul characters'...
(it is an JPEG image data).so if I populate a Char array with the data

'Char' is not a standard C type. You meant 'char'...
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.

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.
Is there any way that send() can ignore the null character and transmit
the entire data in the buffer.

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
 
K

Keith Thompson

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

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.
 
S

SM Ryan

(e-mail address removed) 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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top