structs for data transfer?

From: Oliver Gerlich (olig9_blocker__at_gmx.de)
Date: 09/19/04


Date: Sun, 19 Sep 2004 18:29:40 +0200

Hello,
I want to transfer messages between a client and a server (over TCP
sockets). A message consists of a message type (like a message "subject"
:), the size of the attached data, and the data itself. The data part
should then be able to contain some information whose layout depends on
the message type...
So now I thought I could define some structs which represent the layout
of the additional information, like this:

typedef struct
{
   char versionString[30]
   bool paused;
   int uptime;
} MsgCoreInfoStruct;

And then I use something like this:

MsgCoreInfoStruct myData;
strcpy(myData.versionString, "Server V1.0");
myData.uptime = getUptime();
myData.paused = false;

Message m;
m.setData( (char*)(&myData) , sizeof(myData) );

The Message object then sends the data to the other side.

Question: When I receive such a message, can I just cast the char*
(which points to the data) into MsgCoreInfoStruct* myRecvData?
And can I then use myRecvData->uptime to get the value I sent out?
And, last but not least ;) , can I use this concept if client and server
are running on different platforms (in this case, Linux and Win)?

I have doubts about this (because of data packing, and because
sizeof(bool) might be inconsistent between compilers...), but I'm not
sure...

Can someone tell me if this concept is right or wrong? Or has someone a
better solution for this problem (maybe something else than structs)?

Thanks in advance,
Oliver Gerlich



Relevant Pages

  • Re: What doesnt lend itself to OO?
    ... >> proxy and instructs the server to constuct the real object. ... rather than client code. ... If 'clock' is instantiated in the server, ... > for the server interface at the OOA level. ...
    (comp.object)
  • This is going straight to the pool room
    ... or not the client has privilege to do what they're trying to do, ... The server environment is this: ... 3GL User action Routines that Tier3 will execute on your behalf during the ... Routine Name: USER_INIT ...
    (comp.os.vms)
  • [Full-Disclosure] R: Full-Disclosure Digest, Vol 3, Issue 42
    ... Full-Disclosure Digest, Vol 3, Issue 42 ... SD Server 4.0.70 Directory Traversal Bug ... Arkeia Network Backup Client Remote Access ...
    (Full-Disclosure)
  • Re: What doesnt lend itself to OO?
    ... > rather than client code. ... no way to do that without also touching the object with clock semantics ... will not encapsulate both clock semantics and network semantics. ... The server can do whatever it wants ...
    (comp.object)
  • RE: Fax monitor incoming + outgoing calls?
    ... problem between the client computer and the SBS server. ... Client is using the internal IP address of the SBS server as the ... To the folder redirection GPO issue: ...
    (microsoft.public.windows.server.sbs)