473,566 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

Nov 15 '05 #1
6 13672
<pr***********@ gmail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
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
Nov 15 '05 #2
On 14 Jul 2005 02:40:09 -0700, pr***********@g mail.com
<pr***********@ gmail.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.


(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
Nov 15 '05 #3
> 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)

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

Nov 15 '05 #4
pr***********@g mail.com wrote on 14/07/05 :
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

Nov 15 '05 #5
Stephan Beyer <s-*****@gmx.net> writes:
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)


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) ks***@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.
Nov 15 '05 #6
pr***********@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.
Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
14097
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the byteArray and afterwards see the changes in C#. (if you wanna know more details: the goal is to write the content of an existing char-array in c++...
15
34569
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
8
10701
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to receive a byte array as one of its parameters. The project is marked for COM interop, and that all proceeds normally. When I reference the type...
8
4575
by: frekster | last post by:
Hi. I used to be able to do this easily in vb 6 via looping and preserving the source array data/size etc. How can I do this in vb.net? I've been trying for a while now and this should be an easy task but it just isn't clicking. For some reason, the preserve doesn't seem to be working.
5
9787
by: Robin Tucker | last post by:
I need to marshal an IntPtr (which I've got from GlobalLock of an HGLOBAL) into a byte array. I know the size of the array required and I've got a pointer to the blob, but I can't see how to copy the memory across. Using Marshal.PtrStructure doesn't work - it says my byte() array is not blittable! (byte is a blittable type however). Cannot...
6
2755
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1) using redim arrays to add to a normal byte array (2) using an ArrayList and finally (3) using a memorystream. These three classes are listed below...
17
7226
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need to show the array data to the end user. Can I do that? How?
24
2268
by: ThunderMusic | last post by:
Hi, The subject says it all... I want to use a byte and use it as byte* so I can increment the pointer to iterate through it. What is the fastest way of doing so in C#? Thanks ThunderMusic
10
6355
by: Scott Townsend | last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent it to be in specific places (not yet 100% defined). I wanted to create a structure/class with all of the data in it and then convert that to a byte array, pass it to the device, then get a reply and then convert that to a structure. I'm having issues with making...
2
7192
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the original byte array. What do I need to specify to get Marshal.PtrToStructure to copy the all the data into the "other" array? unsafe public struct DeadReckoning {
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.