Interpolate byte array from 64 bit linux app - Linux

This is a discussion on Interpolate byte array from 64 bit linux app - Linux ; 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 ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Interpolate byte array from 64 bit linux app

  1. Interpolate byte array from 64 bit linux app

    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

  2. Re: Interpolate byte array from 64 bit linux app

    On 2008-08-12, tradevol@yahoo.com wrote:
    > 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

  3. Re: Interpolate byte array from 64 bit linux app

    On Aug 12, 1:58*pm, trade...@yahoo.com wrote:

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


    Okay.

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

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

    > 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

+ Reply to Thread