Article View: borland.public.cppbuilder.internet.socket
Article #1114Re: Serializing struct for TCP sending
From: Bob Gonder
Date: Tue, 15 May 2007 19:00
Date: Tue, 15 May 2007 19:00
42 lines
2485 bytes
2485 bytes
Stefano Bonifazi wrote: >My question is: does that work always on every compiler? Yes, but the results may not be what you want them to be. > May the >procedure of sending that buffer to a program, running on a different >OS, produce a different object on destination even by using the same >struct type on the second program? Yes. See Endian issues. See also alignment issues. > Maybe my problem is silly,and the answer obvious, but I am not sure of >what a compiler does exactly allocating data when I create structures Depends on the alignment setting. The default is probably for your char name[255] to be 256 bytes of storage Most compilers align the internal items for fast processor access. So, a compiler for 8086 might default to byte-alignment while one for pentium would be 4 byte align, and perhaps one for mainframe would be 64 or even 128 bit aligned. This alignment is overridable by the programmer. > and what happen to data when sent by Indy or TCP-IP. It is sent as-is. Bottom line: If you are sending exclusively to your own apps, you can do whatever you want (send raw structures). If you are sending to someone else's app, or your app that someone compiles for their harware, you might be better off converting integers and such into network-endian format and transmit the individual pieces. You might Google this group for endian http://tinyurl.com/28s62e
Technical Details
Message-ID:
<hevj4394fkkbve5uiuicaf1614234a44j3@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!feed10.multikabel.net!multikabel.net!feed20.multikabel.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4649f789@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 From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: Serializing struct for TCP sending Date: Tue, 15 May 2007 12:00:17 -0700 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <hevj4394fkkbve5uiuicaf1614234a44j3@4ax.com> References: <4649f789@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 67.77.147.10 X-Trace: newsgroups.borland.com 1179255615 67.77.147.10 (15 May 2007 12:00:15 -0700) Lines: 44 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!feed10.multikabel.net!multikabel.net!feed20.multikabel.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail