Main Page | Report this Page
 
   
Linux Forum Index  »  Linux Development - Applications  »  Interpolate byte array from 64 bit linux app...
Page 1 of 1    
Author Message
...
Posted: Tue Aug 12, 2008 10:58 am
Guest
Hi,

I have a client app which directly read the byte stream from the
socket, which is sent from linux 64 bit server app.
One problem I have is that I realize that it seems like the minimum
size for the data sent from linux is 4 bytes. even though the server
only sent one char. Any short type data is 8 bytes also (instead of 2
bytes as expected in 32bit system).

One of the reason to use binary array is to reduce the message
traffic. However, it seems unachievable from a 64 bit system.

I sent a lot of data and hope to reduce the size as much as possible,
but still using the 64 bit server. Any suggestions?

Thanks

Chris
Jasen Betts...
Posted: Wed Aug 13, 2008 4:40 am
Guest
On 2008-08-12, tradevol at (no spam) yahoo.com <tradevol at (no spam) yahoo.com> wrote:
Quote:
Hi,

I have a client app which directly read the byte stream from the
socket, which is sent from linux 64 bit server app.
One problem I have is that I realize that it seems like the minimum
size for the data sent from linux is 4 bytes. even though the server
only sent one char. Any short type data is 8 bytes also (instead of 2
bytes as expected in 32bit system).

One of the reason to use binary array is to reduce the message
traffic. However, it seems unachievable from a 64 bit system.

I sent a lot of data and hope to reduce the size as much as possible,
but still using the 64 bit server. Any suggestions?

#pragma pack

in other words check your compiler docs


If that brings no joy use an array of char for the network traffic
and load the numbers you want into it a byte at a time.

it might be a good idea to find some docs on writing portable code.

Bye.
Jasen
David Schwartz...
Posted: Wed Aug 13, 2008 2:59 pm
Guest
On Aug 12, 1:58 pm, trade... at (no spam) yahoo.com wrote:

Quote:
I have a client app which directly read the byte stream from the
socket, which is sent from linux 64 bit server app.

Okay.

Quote:
One problem I have is that I realize that it seems like the minimum
size for the data sent from linux is 4 bytes. even though the server
only sent one char. Any short type data is 8 bytes also (instead of 2
bytes as expected in 32bit system).

The internal representation of data types has nothing to do with how
you send them over the wire.

Quote:
One of the reason to use binary array is to reduce the message
traffic. However, it seems unachievable from a 64 bit system.

You are confusing two different things:

1) Binary packed data versus ASCII data. Like the byte 0x1 versus the
character 1.

2) Binary packed data versus data in the computer's most efficient
internal representation.

Quote:
I sent a lot of data and hope to reduce the size as much as possible,
but still using the 64 bit server. Any suggestions?

Pack and unpack the data exactly how you want it. For example, to pack
a value from 0 to 256 into a single byte, you can use:

void Pack8BitUnsignedValue(void *packet_ptr, int location, int value)
{
(*(unsigned char *)packet_ptr)+location=value;
}

You can make similar functions for other types of values and you can
make 'unpack' functions as well. For example:

void Pack16BitUnsignedValue(void *packet_ptr, int location, int value)
{
(*(unsigned char *)packet_ptr)+location=value/256;
(*(unsigned char *)packet_ptr)+location=value%256;
}

Make appropriate set/get functions for every basic type your protocol
supports. Define your protocol in terms of basic types, define the
basic types in terms of bytes.

DS
 
Page 1 of 1       All times are GMT - 5 Hours
The time now is Wed Dec 03, 2008 6:50 pm