Article View: borland.public.cppbuilder.internet.socket
Article #1120Re: Serializing struct for TCP sending
From: Stefano Bonifazi
Date: Tue, 15 May 2007 21:02
Date: Tue, 15 May 2007 21:02
62 lines
2629 bytes
2629 bytes
Hi Thank U very much!
Remy Lebeau (TeamB) ha scritto:
> my_struct s;
>
> TCPClient->WriteBuffer(s.name, 255);
> TCPClient->WriteInteger(s.intnum);
> // and so on...
>
what I exactly did always :)
> TCPClient->ReadBuffer(s.name, 255);
> s.intnum = TCPClient->ReadInteger();
> // and so on...
Wish they used Indy on Linux..they uses simple Liux socket API.. hope
they perform conversion from Network endian to Host machine endian as
well as!!
>
> Also, you might want to stay away from floating point numbers, if you
> can. The byte size and binary representation may work differently on
> different hardware architectures as well, regardless of the endian
> used.
Engineering numbers are very seldom integers! .. So what to do?
>
>> U mean in "advanced compiler" options, "data alignment" right?
>
> No. That is a global setting that effects the entire application as a
> whole. That would be very dangerous and error-prone.
Oh really?? I wonder why they put the option if that is dangerous!
Thank U!!
What you should
> do instead is wrap your individual structs with #pragma pack
> statements instead, ie:
>
> #pragma pack(push, 1)
> struct my_struct
> {
> //...
> };
> #pragma pack(pop)
>
> Or:
>
> #include <pshpack1.h>
> struct my_struct
> {
> //...
> };
> #include <poppack.h>
Thank U.. never heard about those before!
My best regards!
Stefano B.
Technical Details
Message-ID:
<464a200d@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4649f789@newsgroups.borland.com> <hevj4394fkkbve5uiuicaf1614234a44j3@4ax.com> <464a0555@newsgroups.borland.com> <464a101b@newsgroups.borland.com> <464a1abf@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,fd5a9df59ed83942 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Tue, 15 May 2007 23:02:47 +0200 From: Stefano Bonifazi <stefboombastic@email.it> User-Agent: Mozilla Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: Serializing struct for TCP sending References: <4649f789@newsgroups.borland.com> <hevj4394fkkbve5uiuicaf1614234a44j3@4ax.com> <464a0555@newsgroups.borland.com> <464a101b@newsgroups.borland.com> <464a1abf@newsgroups.borland.com> In-Reply-To: <464a1abf@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 80.104.231.154 Message-ID: <464a200d@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1179262989 80.104.231.154 (15 May 2007 14:03:09 -0700) Lines: 62 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail