Re: Sockets newbie - how do I pass structured data around?
- From: r norman <rsn_@xxxxxxxxxxxx>
- Date: Tue, 05 Jul 2005 07:37:59 -0400
On 5 Jul 2005 04:01:30 -0700, "zardoz" <silangdon@xxxxxxxxxxx> wrote:
>
>I've just followed a CSocket tutorial off Codeproject which seems
>straightforward enough; it passes a file from a server to a client.
>
>I'm more interesting in passing structured data around; can someone
>give me some guidelines? Say I want to pass an object like a class. I'm
>guessing that byte packing and other issues (release / debug versions?)
>mean that passing a chunk of memory (ie pClass to pClass+sizeof(Class))
>to another computer (pCopyOfClass = recieved data buffer) would
>probably heave over.
>
>Thanks
When passing data between systems you have a lot to worry about.
There is structure packing, byte order, size of variables, floating
point representation, character representation, date/time encoding,
etc. If the two systems were produced by the same code and compiler,
you should be OK. At least until you upgrade one system and recompile
with a different version of the compiler but leave the other system
unchanged.
And that is for pure data structures that contain no pointers.
Basically, to really be safe, you must essentially define every byte
of the data stream you pass. If it must contain variable length
structures (strings), define exactly the format of how the receiving
end knows how long the string is and the string encoding.
This is one case where defining user type variables like BYTE, WORD,
SHORT, LONG instead of int, short, long can be very useful -- you
can't count on the language-defined values being the same on both
ends. You can force the user defined values to agree.
.
- Follow-Ups:
- References:
- Prev by Date: Re: new ...delete not working
- Next by Date: Re: Sockets newbie - how do I pass structured data around?
- Previous by thread: Sockets newbie - how do I pass structured data around?
- Next by thread: Re: Sockets newbie - how do I pass structured data around?
- Index(es):
Relevant Pages
|