Re: Little/big endians and sockets



On 2007-02-21, Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx> wrote:
"Roberto Hawkowski" <robertohawkowski@xxxxxxxxxxxx> writes:

Hello,

Assume that we have the following structS2 C/C++ structure to be
communicated amongst various computers via sockets. Some of these
computers are little and the others are big endian machines.

typedef struct {
int A;
bool B;
char C;
float D;
double E;
}struS1;

typedef struct {
struS1 F1;
char F2[19];
}struS2;

Also assume that we want to send/receive these packages at very high
rate (ie, transmission/packing should be efficient).

What practical solution would you recommend for this communication
problem ?

Serialize the data!

The best way to do it is to write it in ASCII, and then to parse it back.

Otherwise, you can serialize it in binary, using ntohl, htonl, ntohs
and htons.

If you go the binary route, you have to be careful to avoid
field alignment and padding problems.

--
Grant Edwards grante Yow! That's a decision
at that can only be made
visi.com between you & SY SPERLING!!
.



Relevant Pages

  • Re: Little/big endians and sockets
    ... communicated amongst various computers via sockets. ... computers are little and the others are big endian machines. ... typedef struct { ... The best way to do it is to write it in ASCII, and then to parse it back. ...
    (comp.os.linux.development.apps)
  • Little/big endians and sockets
    ... communicated amongst various computers via sockets. ... computers are little and the others are big endian machines. ... typedef struct { ... char F2; ...
    (comp.os.linux.development.apps)
  • Re: Little/big endians and sockets
    ... computers are little and the others are big endian machines. ... typedef struct { ... What practical solution would you recommend for this communication ...
    (comp.os.linux.development.apps)