Re: Little/big endians and sockets
- From: Grant Edwards <grante@xxxxxxxx>
- Date: Wed, 21 Feb 2007 22:05:51 -0000
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!!
.
- References:
- Little/big endians and sockets
- From: Roberto Hawkowski
- Re: Little/big endians and sockets
- From: Pascal Bourguignon
- Little/big endians and sockets
- Prev by Date: Re: Little/big endians and sockets
- Next by Date: Re: Loading multiple classes from dynamic linked libraries
- Previous by thread: Re: Little/big endians and sockets
- Next by thread: Re: Little/big endians and sockets
- Index(es):
Relevant Pages
|