🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #1113

Serializing struct for TCP sending

#1113
From: Stefano Bonifazi
Date: Tue, 15 May 2007 18:10
37 lines
2157 bytes
Hi all!:)
  In short I would like to send whole structure instances by using 
TCP-IP.. for example through Indy TCPClient.
The first and secure way is to serialize the members of a structure in a 
buffer and then send them with

procedure WriteBuffer(const ABuffer; AByteCount: Longint; const 
AWriteNow: boolean);

Anyway for simple structures for example:

struct
{
  char name[255];
  int intnum;
  float fnum;
} my_struct;

it seems to work even something like that:

WriteBuffer (&myStruct,sizeof(my_struct));

that means that in memory they are simply placed one right the other.. 
so on the other side I can receive the buffer by knowing that structure 
size, and cast the buffer to that struct pointer!

My question is: does that work always on every compiler? 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?

  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 or 
classes, and what happen to data when sent by Indy or TCP-IP.

Thank U very much in advance,
Stefano B.
Technical Details
Message-ID: <4649f789@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!newsfeed0.kamp.net!newsfeed.kamp.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,fd5a9df59ed83942,start
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Tue, 15 May 2007 20:10:20 +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: Serializing struct for TCP sending
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 80.104.231.154
Message-ID: <4649f789@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1179252617 80.104.231.154 (15 May 2007 11:10:17 -0700)
Lines: 37
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!newsfeed0.kamp.net!newsfeed.kamp.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail